Table stylesheet: How do I style table items?

Find and share HowTos to various installations / configurations!
Search

Post Reply
6 posts • Page 1 of 1
User avatar
joost.lijster@siemens.com
Posts: 19
Joined: Wed Sep 21, 2016 1:51 pm

Table stylesheet: How do I style table items?

Post by joost.lijster@siemens.com »

Hi all,

As already mentioned in this thread about frame styling, CSS / QSS offers a lot of possibilities when it comes to styling.

One thing that i have never succeeded in however, is styling Table items (rows). Many widgets support item styling, such as the Listview and treeviews/typeviews, but not the table. For example, i have created a simple panel with an extremely simple stylesheet (see image attached below).

Code: Select all

*::item:hover {
  background-color: red;
}
*::item:selected {
  background-color: purple;
}
The listview responds to hover, just as the other items, but the table items refuse to show any styling. It would definitely be a big big plus if tables could be styled completely. Is there anything that could get styling on tables to work?


Also, the treeviews have the QProperty "stretchLastSection" enabled, which causes the last column to fill the entire width of the widget. The Table also supports this feature, which can be enabled through CSS:

Code: Select all

QHeaderView {
    qproperty-stretchLastSection: 1;
}
Using this feature stretches the last column nicely to fill the entire table. The downside is, that a row header is also considered as a QHeaderView::section, causing the last row to stretch as well (or sometimes the first one). The effect is also visible in the screenshot. Is there any way this can be set to just the horizontal header, for example through scripting?

With kind regards,

Joost

Image
Attachments
table_item_styling.png

Gertjan van Schijndel
Posts: 634
Joined: Mon Aug 02, 2010 10:37 am

Re: Table stylesheet: How do I style table items?

Post by Gertjan van Schijndel »

To stretch the a table column you can use the 'columnStretchable' function/property.

User avatar
joost.lijster@siemens.com
Posts: 19
Joined: Wed Sep 21, 2016 1:51 pm

Re: Table stylesheet: How do I style table items?

Post by joost.lijster@siemens.com »

Thanks Gertjan!

The function seems to solve one of the problems. According to the description of this function in the Help-file, I wouldn't have guessed this result. "Allows you to adjust the width of a table column" made me think the function was a duplicate of "enableColumnResize".

Then there is still the part about styling the table rows, which would save a lot of work to get the requested visual results for a table. Is there any reason why most of the QT widgets do respond to the "::item" selector in CSS, but the table doesn't?

User avatar
mkoller
Posts: 741
Joined: Fri Sep 17, 2010 9:03 am

Re: Table stylesheet: How do I style table items?

Post by mkoller »

Just a rough guess since I did not check details:
Our Table widget can be given a lot of graphical attributes, font, color, background, etc, per row, color or cell.
For this we use an own implementation of a delegate to render all this different things.
Therefore these settings are used and not the stylesheet.

User avatar
joost.lijster@siemens.com
Posts: 19
Joined: Wed Sep 21, 2016 1:51 pm

Re: Table stylesheet: How do I style table items?

Post by joost.lijster@siemens.com »

Thanks for the information, sounds like a valid reason why stylesheets have no effect on the table widget. A bit of trying learns that the tree-widget has the same behavior.

The reason why I asked is the lack of a mouse-over coloring event, so in order to implement this, the stylesheet seemed like the only solution. The table knows a function which sets the selection background color, but not a function that applies a hover effect. Is there any chance / are there any plans that hover color events (like the .selectColors function of the table) will be implemented?

With kind regards,

Joost

User avatar
joost.lijster@siemens.com
Posts: 19
Joined: Wed Sep 21, 2016 1:51 pm

Re: Table stylesheet: How do I style table items?

Post by joost.lijster@siemens.com »

(as to complete this thread; solution is on its way, for more information see This post)

Post Reply
6 posts • Page 1 of 1