Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change color highlight of icons in QTableView, when the cell is selected

When a cell is selected in QTableView, the icons in it are given a blue highlight, how can I control the color of this highlight or disable it?

I tried setting the QPalette::Highlight but it didn't work.

Edit:

Okay, so I do know how to change the background color and text color and color highlight, but not for an icon. If I return an icon as decoration for a cell, it is given a light blue highlight when the cell is selected. How do I remove this?

like image 385
0xbaadf00d Avatar asked Dec 20 '13 11:12

0xbaadf00d


1 Answers

You can use style sheets to define the color of your elements. The name of the selected item in your QTableView is selection-background-color. So, changing the color of this element you will chose the background color that your prefer.

#include <QtWidgets/QApplication>
#include <QtWidgets/QTableView>
#include <QStandardItemModel>

int main(int argc, char* argv[]) {
    QApplication app(argc, argv);

    QTableView *table = new QTableView();
    QStandardItemModel *model = new QStandardItemModel(2,2);

    table->setModel(model);
    table->setStyleSheet("selection-background-color: red");

    table->show();

    return app.exec();
}

Look how it looks in the picture:

enter image description here

like image 57
Eliezer Bernart Avatar answered Sep 18 '22 21:09

Eliezer Bernart