Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTreeView problem
Forum Updated to NodeBB v4.3 + New Features

QTreeView problem

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 1.7k 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.
  • malchM Offline
    malchM Offline
    malch
    wrote on last edited by
    #1

    For various reasons I wish to hide the expand/collapse arrows on my QTreeView derived class. So I used a stylesheet:

    QTreeView::branch {image: none;}
    

    This looks nice and it's still nice when I select an item in the tree. But when I move focus away from the tree the background color of the selected row changes appropriately, but the background under expand/collapse indicator does not.

    No matter what I try, I just can't get control over the the background color of that portion in the selected:!focus state.

    Suggestions would be welcome. Here's an easy way to see the problem:

    Open the "treemodelcompleter" demo.

    In mainwindow.cpp add following line after the new QTreeview (at approx line 98).

    treeView->setStyleSheet("QTreeView::branch {image: none;}");
    

    Run the program and select one of the Grandchildren in the tree. The hit tab to move focus and you'll see the selected row has two different background colors.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi
      im not sure im seeing it?
      http://s7.postimg.org/wq8lixxuj/screenshot_8.png
      win 10. Qt 5.6

      1 Reply Last reply
      0
      • malchM Offline
        malchM Offline
        malch
        wrote on last edited by malch
        #3

        Thanks for that.

        I think it depends on what you see when the row is selected and the QTreeView has focus. Is the entire row selected? Or just "Grandchild" and everything to the right of it.

        Here's what I get with and without focus:

        http://malch.com/nikon/cap1.png

        http://malch.com/nikon/cap2.png

        This with Linux Mint Xfce 17.3 and Qt 5.6.

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          hi
          well, picture is done after click grandchild, press tab.

          with this
          treeView->setStyleSheet("QTreeView::branch {image: none;} QTreeView::branch:selected {background-color: yellow;}");

          I can make that part yellow so may u can cheat that way?
          (using white)

          1 Reply Last reply
          1
          • malchM Offline
            malchM Offline
            malch
            wrote on last edited by malch
            #5

            Thanks but it doesn't really help because I can't seem to get control of the background in the focused and not focused states. Therefore I can't keep the color consistent with the other row item(s).

            Going back to the basic image: none; style, I did make another very interesting observation. If I resize the treemodelcompleter window, the colors are great while dragging. As soon as I stop dragging, I'm back to the same problem.

            Seems to me there is something funky going on with the painting of the background in the branch:: region with no image.

            Perhaps I will poke around in the QTreeView source code when time permits although that may be in a few days to week. In the meantime, I appreciate you taking a look. Thank you!

            1 Reply Last reply
            0
            • malchM Offline
              malchM Offline
              malch
              wrote on last edited by
              #6

              Well, this solved the problem rather nicely and easily :

              void MyTreeView::drawBranches(QPainter *painter, const QRect &rect, const QModelIndex &index) const
              {
              }
              

              :-)

              1 Reply Last reply
              1

              • Login

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