WTableView/WItemDelegate custom

Added by Ulf Johnsson 17 days ago

I cannot seem to wrap my head around how to create a properly working delegate.

In my program I have a WTableView that at the moment uses a WItemDelegate.
I am trying to create a custom delegate that is very similar to the WItemDelegate,
except for that I want my delegate to have borders and a different background color/selected color.

Is there a way to change the selected-color? I know it utilizes the style-class "Wt Selected" to set this color.
Right now I am using the WCssDecorationStyle class on the widget in the delegate, but doing so "brakes" the
selection-color, since its "selected-class" will no longer apply.


BR, Ulf.

Replies (3)

RE: WTableView/WItemDelegate custom - Added by Koen Deforche 17 days ago

Hey Ulf,

If it's just about changing the color, you should use CSS to override the default color associated with the "wt-selected" style class?
Changing border color should be okay too, but changing border width can be tricky as it could mess up the layout of the table.


RE: WTableView/WItemDelegate custom - Added by Ulf Johnsson 16 days ago

I was thinking if using Wt::WWidget::addStyleClass to shadow the default background, end this class would itself get shadowed
by the "Wt Selected" style when active, seems to work. The only drawback is that I have to register the style globally :/

Can I change the style-sheet "Wt Selected" locally for a specific table-view? I do not want to change the look for every object using this style-sheet...

BR, Ulf.

RE: WTableView/WItemDelegate custom - Added by Wim Dumon 15 days ago


That is certainly possible by using CSS selectors. By embedding your tableview in a wcontainerwidget with a particular style class ('myclass'), you can easily write a CSS selector that says 'all wt-selected inside of myclass':

.myclass .wt-selected {

There are many more CSS selectors and the system is quite powerful to style applications. Note that I don't think it will be necessary to wrap the tableview in another container, simply adding the class to the tableview is probably enough (since wt-selected will already be in child node of the tableview).