How to remove default blue selection of QTreeWidget ?
Unsolved
General and Desktop
-
I have a QTreeWidget with rows having some colors. When I try to select row (using mouse click) row's color changes to blue.
(I have clicked on middle row)
To avoid change in color, I used following property of QTreeWidgetui->treeWidget->setSelectionMode(QAbstractItemView::NoSelection);
After adding this, color changing issue was solved.
(I have clicked on middle row )
But because of this, another issue came up. By adding
ui->treeWidget->setSelectionMode(QAbstractItemView::NoSelection);
which means, there will not be any selection. And due to this, on Right mouse click, I have some options ( copy text , copy hierarichal path etc ) are not working. (Because row is not getting selected )
How to solve above problem ?
Here is my code :
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); displayTree(); } void MainWindow::displayTree() { ui->treeWidget->setColumnCount(4); QStringList labels; labels << "Instance" << "Domains" << "Model" <<"Model Type"; ui->treeWidget->setHeaderLabels(labels); ui->treeWidget->setSelectionMode(QAbstractItemView::NoSelection); QTreeWidgetItem* root = new QTreeWidgetItem(ui->treeWidget); root->setText(0,"top"); root->setText(2,"top"); root->setText(3,"Module"); ui->treeWidget->addTopLevelItem(root); QTreeWidgetItem* child1 = new QTreeWidgetItem(); child1->setText(0,"U1"); child1->setText(1,"PD1"); child1->setText(2,"lvds_system"); child1->setText(3,"Module"); root->addChild(child1); // adding more data in tree same as above }