[SOLVED][Python/PyQt] How to get rid of "white highlight/box" in QTreeWidgetItem Row?
-
hi everyone,
Does anyone know how to get rid of the "white highlight/box" in the QTreeWidgetItem Row:
!http://i44.tinypic.com/2ep4nqs.png(gui)!
This happens when I select the row.
Any ideas?
Please help!
Thanks so much!!!!
-
Is this part of the QTreeWidget's horizontal header of is it a 'cell/row' in tree itself? If its in the table, this may just be the normal selection behaviour? If so you can either switch off selection of use stylesheets to change the selection colour. If you can provide a little code example, we might be able to help you further.
Hope this helps ;o)
-
It is a cell/row in the QTreeWidget.
Here is some code:
@ #!/usr/bin/env python
from PyQt4.QtCore import *
from PyQt4.QtGui import *class MainWindow(QMainWindow):
def init(self, parent=None, **kwargs):
QMainWindow.init(self, parent=None, **kwargs)self.setStyleSheet(""" QTreeView::item { background-color: rgb(49,49,49); border-left: 1px solid rgb(40,40,40); } QTreeView::item::selected { background-color: rgb(103,95,92); color: rgb(40,40,40); } QTreeView QHeaderView:section { background-color: rgb(44,44,44); color: rgb(133,133,133); } """) self.tree = QTreeWidget(self) self.tree.resize(300,300) self.parent = QTreeWidgetItem(self.tree, "test") self.child = QTreeWidgetItem(self.parent, ["test", "test", "test"])
if name=="main":
from sys import argv, exita=QApplication(argv) m=MainWindow() m.resize(300,300) m.show() m.raise_() exit(a.exec_())
@
I also tried selection-background-color in the stylesheet, same result.
Please select child item to reproduce issue.
Thanks:)!
-
I believe what you're looking for is the 'branch' selector. For example, the following would colour your problem area blue:
@
QTreeView::branch {
background: blue;
}
@A description of this and examples of the various sub selectors can be found "here":http://qt-project.org/doc/qt-4.8/stylesheet-examples.html#customizing-qtreeview.
Hope this helps ;o)
-
You're a genius, Jazzy! :)
You save the day again...
-
You can use the ':alternate' selector for both items and branches as below:
@
from PyQt4.QtCore import *
from PyQt4.QtGui import *class MainWindow(QMainWindow):
def init(self, parent=None, **kwargs):
QMainWindow.init(self, parent=None, **kwargs)self.setStyleSheet(""" QTreeView::item { background-color: rgb(49,49,49); border-left: 1px solid rgb(40,40,40); } QTreeView::item:alternate { background: rgb(98,98,98); } QTreeView::item::selected { background-color: rgb(103,95,92); color: rgb(40,40,40); } QTreeView QHeaderView:section { background-color: rgb(44,44,44); color: rgb(133,133,133); } QTreeView::branch { background: rgb(49,49,49); } QTreeView::branch:alternate { background: rgb(98,98,98); } QTreeView::branch::closed::has-children { image: url(branch-closed.png); } QTreeView::branch::open::has-children { image: url(branch-open.png); } """) self.tree = QTreeWidget(self) self.tree.setAlternatingRowColors(True) self.tree.resize(300,300) self.parent = QTreeWidgetItem(self.tree, "test") self.child = QTreeWidgetItem(self.parent, ["test", "test", "test"])
if name=="main":
from sys import argv, exita=QApplication(argv) m=MainWindow() m.resize(300,300) m.show() m.raise_() exit(a.exec_())
@
Hope this helps ;o)
-
Another question regarding the indentation : )
I have one child that has a QWidgets set for all the columns in a row (each row has it's own QWIdget)... It has some gradient in the background. And then the indentation is just a solid color depending on what row it gets to.. Is there a way that I can set QWidget to cover that indentation? (I tryed simpliest: QWidget.move(-30, 0) but that didn't work :) ) Do I have to make a Delegate or can I avoid that?