Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. [SOLVED][Python/PyQt] How to get rid of "white highlight/box" in QTreeWidgetItem Row?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED][Python/PyQt] How to get rid of "white highlight/box" in QTreeWidgetItem Row?

Scheduled Pinned Locked Moved Language Bindings
9 Posts 3 Posters 7.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    needhelp_gh
    wrote on 5 Jul 2013, 23:49 last edited by
    #1

    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!!!!


    http://abstrusegoose.com/432

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jazzycamel
      wrote on 10 Jul 2013, 07:39 last edited by
      #2

      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)

      For the avoidance of doubt:

      1. All my code samples (C++ or Python) are tested before posting
      2. As of 23/03/20, my Python code is formatted to PEP-8 standards using black from the PSF (https://github.com/psf/black)
      1 Reply Last reply
      0
      • N Offline
        N Offline
        needhelp_gh
        wrote on 10 Jul 2013, 16:44 last edited by
        #3

        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, exit

        a=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:)!


        http://abstrusegoose.com/432

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jazzycamel
          wrote on 10 Jul 2013, 17:09 last edited by
          #4

          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)

          For the avoidance of doubt:

          1. All my code samples (C++ or Python) are tested before posting
          2. As of 23/03/20, my Python code is formatted to PEP-8 standards using black from the PSF (https://github.com/psf/black)
          1 Reply Last reply
          0
          • N Offline
            N Offline
            needhelp_gh
            wrote on 10 Jul 2013, 17:13 last edited by
            #5

            You're a genius, Jazzy! :)

            You save the day again...


            http://abstrusegoose.com/432

            1 Reply Last reply
            0
            • A Offline
              A Offline
              Alena
              wrote on 19 Mar 2014, 23:11 last edited by
              #6

              What if I have QTreeWidget that has altenateRowColors so I cannot put it to be only one color... :(
              Anyone has a solution for that?

              1 Reply Last reply
              0
              • J Offline
                J Offline
                jazzycamel
                wrote on 20 Mar 2014, 08:46 last edited by
                #7

                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, exit

                a=QApplication(argv)
                m=MainWindow()
                m.resize(300,300)
                m.show()
                m.raise_()
                exit(a.exec_())
                

                @

                Hope this helps ;o)

                For the avoidance of doubt:

                1. All my code samples (C++ or Python) are tested before posting
                2. As of 23/03/20, my Python code is formatted to PEP-8 standards using black from the PSF (https://github.com/psf/black)
                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  Alena
                  wrote on 20 Mar 2014, 15:19 last edited by
                  #8

                  Hahaha I was sooo close :) i was trying alternate-background-color instead of adding alternate on a class :) Thank you soo much :) It did help :)

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    Alena
                    wrote on 20 Mar 2014, 16:07 last edited by
                    #9

                    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?

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved