highlighting hovered QListWidget item
Me again.
I have QListWidget where I want to highlight hovered item. The problem is, when I try to do so using CSS, it doesn't work - background color isn't changing on hover. My code:
Code:
int numRecentFiles = qMin(files.size(), 5);
for (int i = 0; i < numRecentFiles; i++)
{
}
listWidget->setMouseTracking(true);
listWidget->setStyleSheet("QListWidget::item:hover {background-color:yellow;}");
I've also tried to succeed with signal-slot mechanism and I must say, almost did it. The problem is, when cursor leaves the widget, highlight stays at the last hovered element, because I don't know how to use the 'viewport left event'. I would be grateful if someone could provide me some example. (lol, I ended this sentence with semicolon and pushed Ctrl+S).
Thanks in advance
EDIT: Well, right after posting I answered myself the first question. Instead of
Code:
listWidget->setStyleSheet("QListWidget::item:hover {background-color:yellow;}");
I should write
Code:
this->setStyleSheet("QListWidget::item:hover {background-color:yellow;}");
but I don't like the effect.
Second question still active though.
Re: highlighting hovered QListWidget item
this example shows 'background' not 'background-color'
Re: highlighting hovered QListWidget item
Quote:
Originally Posted by
amleto
this example shows 'background' not 'background-color'
For a single attribute, it is recommended to use specified names.
I managed to achieve the wished effect. Firstly, I was not satisfied with CSS hovering because background wasn't expanding to margins, so I changed margin to padding and now it's ok.
Problem solved (I still don't know how to use viewport, but it's a thing for another story ;))