QListWidget disable hover for item widget?
-
wrote on 5 May 2023, 12:38 last edited by Taytoo 5 May 2023, 12:39
I'm using setItemWidget to set a widget for each item added to QListWidget. How do I disable hover effect for specific items/itemwidgets?
I've tried using stylesheet as proposed in other solutions but that doesn't work.
-
@SGaist said in QListWidget disable hover for item widget?:
@Taytoo your original stylesheet does not apply to items of an item view.
Try something like:QListWidget::item:hover, QListWidget::item:disabled:hover, QListWidget::item:hover:!active, {background: transparent;}
Experimented a bit using this stylesheet. It works Only on Enabled items. If I remove IsSelectable flag or IsEnabled flag, then the stylesheet doesn't work and normal hover effect is shown.
I've even tried disabling the widget that I'm setting for the item using setItemWidget, still didn't work.wrote on 9 May 2023, 06:14 last edited by Taytoo 5 Sept 2023, 09:20Finally, found a solution! The trick is Not to use hover modifier/attribute for disabled items
QListWidget::item:disabled, QListWidget::item:!active, {background: transparent;}
This stylesheet plus removing IsEnabled or IsSelectable flag for desired items will disable hover effect.
-
I'm using setItemWidget to set a widget for each item added to QListWidget. How do I disable hover effect for specific items/itemwidgets?
I've tried using stylesheet as proposed in other solutions but that doesn't work.
Hi,
What exactly are you trying to do with your list widget ? As noted in the documentation and many posts on this forum, it should not be used beside showing some static content. If you need one widget per element then you should rather implement a custom QStyledItemDelegate.
-
I'm using setItemWidget to set a widget for each item added to QListWidget. How do I disable hover effect for specific items/itemwidgets?
I've tried using stylesheet as proposed in other solutions but that doesn't work.
-
Hi,
What exactly are you trying to do with your list widget ? As noted in the documentation and many posts on this forum, it should not be used beside showing some static content. If you need one widget per element then you should rather implement a custom QStyledItemDelegate.
wrote on 6 May 2023, 15:07 last edited by@SGaist said in QListWidget disable hover for item widget?:
Hi,
What exactly are you trying to do with your list widget ?
It will be used to show static content, typically around 5 items. I'm using setItemWidget since its much simpler than QStyledItemDelegate.
Only issue is that I'm insert a dummy item/widget for visual separation of certain items but when mouse moves over the dummy item/widget, there is hover (blue background) effect on that as well and I'd like to disable it. -
@Taytoo I guess the widget is on top of QListWidget item. Can you try to disable hovering for that widget(not list item) with style sheet since list item is empty(nullptr) in the cell of widget?
wrote on 6 May 2023, 15:08 last edited by@JoeCFD said in QListWidget disable hover for item widget?:
@Taytoo I guess the widget is on top of QListWidget item. Can you try to disable hovering for that widget(not list item) with style sheet since list item is empty(nullptr) in the cell of widget?
I tried following in stylesheet but didn't work:
QWidget::hover, QWidget::disabled:hover, QWidget::hover:!active, {background: transparent;}
-
@JoeCFD said in QListWidget disable hover for item widget?:
@Taytoo I guess the widget is on top of QListWidget item. Can you try to disable hovering for that widget(not list item) with style sheet since list item is empty(nullptr) in the cell of widget?
I tried following in stylesheet but didn't work:
QWidget::hover, QWidget::disabled:hover, QWidget::hover:!active, {background: transparent;}
wrote on 6 May 2023, 15:45 last edited by JonB 5 Jun 2023, 15:45@Taytoo
Just a thought: is that "blue background" a hover for the cell/table, not the widget? Does your "empty"QWidget
fill the cell? Because if it is "tiny" with no content maybe what you are seeing is cell background? I don't know. -
@Taytoo
Just a thought: is that "blue background" a hover for the cell/table, not the widget? Does your "empty"QWidget
fill the cell? Because if it is "tiny" with no content maybe what you are seeing is cell background? I don't know. -
@JonB Widget is as wide as QListWidget, but the QLabel is centered inside it (not stretched to edges of Widget).
@Taytoo what are you showing ? Text ? Images ?
-
If it's just a background issue, just set the corresponding role in your model. It will simplify everything.
-
If it's just a background issue, just set the corresponding role in your model. It will simplify everything.
-
@SGaist What do you mean by set the corresponding role? I'm just adding items to QListWidget, not using Model/View like you have to with QListView
wrote on 8 May 2023, 07:37 last edited by- For a
QListWidget
anyQListWidgetItem
can call void QListWidgetItem::setBackground(const QBrush &brush). - Or
listWidget->model()->setData(index, brush, Qt::BackgroundRole)
should do it. - Or you could interpose a
QAbstractProxyModel
between theQListWidget
and its suppliedmodel()
, where your proxy model overridesdata()
method to return the brush for theQt::BackgroundRole
role.
For the brush I think you can use
QBrush(Qt::transparent)
or perhaps plainQt::transparent
. - For a
-
- For a
QListWidget
anyQListWidgetItem
can call void QListWidgetItem::setBackground(const QBrush &brush). - Or
listWidget->model()->setData(index, brush, Qt::BackgroundRole)
should do it. - Or you could interpose a
QAbstractProxyModel
between theQListWidget
and its suppliedmodel()
, where your proxy model overridesdata()
method to return the brush for theQt::BackgroundRole
role.
For the brush I think you can use
QBrush(Qt::transparent)
or perhaps plainQt::transparent
. - For a
-
@JoeCFD said in QListWidget disable hover for item widget?:
@Taytoo I guess the widget is on top of QListWidget item. Can you try to disable hovering for that widget(not list item) with style sheet since list item is empty(nullptr) in the cell of widget?
I tried following in stylesheet but didn't work:
QWidget::hover, QWidget::disabled:hover, QWidget::hover:!active, {background: transparent;}
-
@JonB I'm a bit confused, how would setting the background brush disable Hover effect on QListWidget item widget?
wrote on 8 May 2023, 15:55 last edited by JonB 5 Aug 2023, 15:55@Taytoo said in QListWidget disable hover for item widget?:
@JonB I'm a bit confused, how would setting the background brush disable Hover effect on QListWidget item widget?
I was just (hopefully, unless I got it wrong) fleshing out:
@SGaist said in QListWidget disable hover for item widget?:If it's just a background issue, just set the corresponding role in your model. It will simplify everything.
when you asked
@SGaist What do you mean by set the corresponding role?
Perhaps he will explain if that simplifies things :)
-
@Taytoo said in QListWidget disable hover for item widget?:
@JonB I'm a bit confused, how would setting the background brush disable Hover effect on QListWidget item widget?
I was just (hopefully, unless I got it wrong) fleshing out:
@SGaist said in QListWidget disable hover for item widget?:If it's just a background issue, just set the corresponding role in your model. It will simplify everything.
when you asked
@SGaist What do you mean by set the corresponding role?
Perhaps he will explain if that simplifies things :)
wrote on 8 May 2023, 15:59 last edited by@JonB Tried setting Background brush on Item. It has no effect on hover. If I change the background to Red, then item background is colored Red, but moving mouse over the widget still shows the hover effect (bluish color).
I'm starting to think maybe its a Qt bug or Qt on Windows 10 issue, because the suggested stylesheet fixes aren't working at all.
-
@JonB Tried setting Background brush on Item. It has no effect on hover. If I change the background to Red, then item background is colored Red, but moving mouse over the widget still shows the hover effect (bluish color).
I'm starting to think maybe its a Qt bug or Qt on Windows 10 issue, because the suggested stylesheet fixes aren't working at all.
@Taytoo your original stylesheet does not apply to items of an item view.
Try something like:QListWidget::item:hover, QListWidget::item:disabled:hover, QListWidget::item:hover:!active, {background: transparent;}
-
@Taytoo your original stylesheet does not apply to items of an item view.
Try something like:QListWidget::item:hover, QListWidget::item:disabled:hover, QListWidget::item:hover:!active, {background: transparent;}
wrote on 8 May 2023, 20:29 last edited by@SGaist I'm able to get hover effect to work if I remove the disabled modifier in stylesheet. But if an Item is disabled using code below (hoping this is correct way of disabling an item?), then the stylesheet doesn't work.
item->setFlags(item->flags() & ~Qt::ItemIsEnabled);
-
@Taytoo your original stylesheet does not apply to items of an item view.
Try something like:QListWidget::item:hover, QListWidget::item:disabled:hover, QListWidget::item:hover:!active, {background: transparent;}
wrote on 9 May 2023, 05:56 last edited by Taytoo 5 Sept 2023, 05:57@SGaist said in QListWidget disable hover for item widget?:
@Taytoo your original stylesheet does not apply to items of an item view.
Try something like:QListWidget::item:hover, QListWidget::item:disabled:hover, QListWidget::item:hover:!active, {background: transparent;}
Experimented a bit using this stylesheet. It works Only on Enabled items. If I remove IsSelectable flag or IsEnabled flag, then the stylesheet doesn't work and normal hover effect is shown.
I've even tried disabling the widget that I'm setting for the item using setItemWidget, still didn't work. -
@SGaist said in QListWidget disable hover for item widget?:
@Taytoo your original stylesheet does not apply to items of an item view.
Try something like:QListWidget::item:hover, QListWidget::item:disabled:hover, QListWidget::item:hover:!active, {background: transparent;}
Experimented a bit using this stylesheet. It works Only on Enabled items. If I remove IsSelectable flag or IsEnabled flag, then the stylesheet doesn't work and normal hover effect is shown.
I've even tried disabling the widget that I'm setting for the item using setItemWidget, still didn't work.wrote on 9 May 2023, 06:14 last edited by Taytoo 5 Sept 2023, 09:20Finally, found a solution! The trick is Not to use hover modifier/attribute for disabled items
QListWidget::item:disabled, QListWidget::item:!active, {background: transparent;}
This stylesheet plus removing IsEnabled or IsSelectable flag for desired items will disable hover effect.
-
1/20