Change Highlight item's color if a QListWidgetItem
-
Hi, I have created a QListWidget dynamically to populate menu items and allow user to select them and access different functions.
The code is as follows:
QListWidgetItem* homePage = new QListWidgetItem(tr("HOME")); QListWidgetItem* productPage = new QListWidgetItem(tr("PRODUCTS")); QListWidgetItem* locationPage = new QListWidgetItem(tr("LOCATIONS")); ui.listWidget->insertItem(0, homePage); ui.listWidget->insertItem(1, productPage); ui.listWidget->insertItem(2, locationPage); ui.listWidget->setCurrentRow(0);
How do i go about changing the set current row highlighted color?? Please advise. Thank you.
-
You can use QPalette or a Stylesheet for that. I would recommen a simple Stylesheet. Something like
ui.listWidget->setStylesheet("QListWidget:item { selection-background-color: blue; }"
I dont know if that Code works, but something like this. You can set the Stylesheet in the Form through Qt Creater as well.
-
Hi,
Please take a look at the stylesheet reference for QListView. It shows how to customize several aspects of that widget.
-
@qt-1234 said in Change Highlight item's color if a QListWidgetItem:
@Fuel-0 it does not work even if i use QListWidget.
maybe you set this style sheet in wrong widget.
try this:ui->listWidget->setStyleSheet("QListView::item:selected{background-color: rgb(255,0,0);}");
if not work again maybe your IDE is have a problem.
good luck