QTableWidgetItem set background color on click (over stylesheet )
-
@JonB this would be the thing if I could get
QWidget
presentation ofQTableWidgetItem
, but then I would just set background color of widget.QTableWidgetItem
itself doesn't contain membersetProperty
(or similar), so I can't achieve what I want in your way. Thanks for advice tho, didn't know about widget dynamic properties. -
@nevdokimof said in QTableWidgetItem set background color on click (over stylesheet ):
@JonB this would be the thing if I could get
QWidget
presentation ofQTableWidgetItem
, but then I would just set background color of widget.Even then I thought that would not work as your stylesheet rule would override your code setting of background color?
QTableWidgetItem
itself doesn't contain membersetProperty
(or similar), so I can't achieve what I want in your way. Thanks for advice tho, didn't know about widget dynamic properties.Darn, I forgot those are not
QWidget
s... :( I'm having a think, if I have anything to add I'll get back.... -
I want to change item background color when user clicks on it.
When user clicks that "selects" the item, doesn't it? So have you tried
QTableWidget::item:selected
rule instead? -
@JonB I don't want to allow user "select" (as Qt means it) items. In my case items are supposed to behave like regural push buttons.
The reason why I don't use
QPushButton
s + vertical layout (or whatever) in first place is scroll bar inQTableWidget
. -
@nevdokimof
Given that we're not achieving what you originally asked for: if you just want a scrollbar, what about using aQScrollArea
around yourQPushButton
s' layout, which is how to get a lightweight scroller without needingQTableWidget
? -
@nevdokimof
I believe your original question is indeed answered: "No, you cannot alterQTableWidgetItem
dynamically while using a stylesheet precisely because it is not aQWidget
".
Sample reference: https://forum.qt.io/topic/13124/solved-qtablewidgetitem-set-stylesheet/4 -
@fouad20013
Previously you talked aboutQTable...
, now you're sayingQTree....
. But the same is the case either way.QTableWidget
inheritsQTableView
. It should be the case that anythingQTableWidget
does you could do yourself usingQTableView
. TheQ...Widget
s are effectively just a convenience implementation off theQ...View
, they provide an "item-based table view with a default model" if that's what you want.However, I think you will have the same issues whether you use a
QTableView
or aQTableWidget
. Why do you think aQTableView
/QTreeView
would solve your issue? -
I came cross the same problem. Any solution? After stylesheet is set for QTableWidgetItem, it seems impossible to change anything for example: background color. "QTableView::item{color:%5;border-color:%6;border:0px;padding-left:%7px;}" is used in qtablewidget and I would like to set different background color for every another row. Without stylesheet, padding can not be set.