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:
int numRecentFiles = qMin(files.size(), 5);
for (int i = 0; i < numRecentFiles; i++)
{
}
listWidget->setMouseTracking(true);
listWidget->setStyleSheet("QListWidget::item:hover {background-color:yellow;}");
QStringList files = Settings->recentFiles();
int numRecentFiles = qMin(files.size(), 5);
for (int i = 0; i < numRecentFiles; i++)
{
listWidget->addItem(new QListWidgetItem(files[i]));
}
listWidget->setMouseTracking(true);
listWidget->setStyleSheet("QListWidget::item:hover {background-color:yellow;}");
To copy to clipboard, switch view to plain text mode
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
listWidget->setStyleSheet("QListWidget::item:hover {background-color:yellow;}");
listWidget->setStyleSheet("QListWidget::item:hover {background-color:yellow;}");
To copy to clipboard, switch view to plain text mode
I should write
this->setStyleSheet("QListWidget::item:hover {background-color:yellow;}");
this->setStyleSheet("QListWidget::item:hover {background-color:yellow;}");
To copy to clipboard, switch view to plain text mode
but I don't like the effect.
Second question still active though.
Bookmarks