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 vertical scrollbar
Forum Updated to NodeBB v4.3 + New Features

qtreeview vertical scrollbar

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 2.2k Views 2 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.
  • Q Offline
    Q Offline
    Qt.Jo.Ha
    wrote on last edited by
    #1

    hello i have treeview

    I want to put the scroll bar on the right.

    MyStyleSheet is this
    QTreeView{border : none; background-color : %4; outline :0; padding-left : 24px; padding-right : 24px;}

    If i give the view an padding Scroll bar follows

    How can I make the scroll bar close to the right?

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

      Hi,

      On the right of what ?
      QTreeView's scroll bars are by default on the right for the vertical one and on the bottom for the horizontal one.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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

        Hi
        Just remove the right padding. Since it the thing that gives the gap anyway.

        alt text

        The scrollbar is next to the internal viewport so padding the QTreeWidget itself will produce a empty space.

        1 Reply Last reply
        1
        • SGaistS SGaist

          Hi,

          On the right of what ?
          QTreeView's scroll bars are by default on the right for the vertical one and on the bottom for the horizontal one.

          Q Offline
          Q Offline
          Qt.Jo.Ha
          wrote on last edited by Qt.Jo.Ha
          #4

          @SGaist @mrjj
          thank you for your answer

          I adjusted the size of the Treeview item, but when I give the padding to the TreeView, a scroll bar follows.

          I want it to look like the following picture (Currently the scroll bar is attached to the side of the item )
          1554356b-2a83-4a47-a1f7-1e2e31c4b1fd-image.png

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

            Hi
            The QTreeView is a QAbstractScrollArea which actually handles the items with its viewport()
            so you cant change it via QTreeView in stylesheet
            as its not the one that draws the items, nor the one that has the scrollbars.

            From a fast test with

            QAbstractScrollArea {
            border : none; background-color : red; outline :0; padding-left : 24px; padding-right : 0px;
            }
            

            and in code
            ui->treeView->viewport()->setStyleSheet("padding-right : 24px;" );

            I get this which you might be able to tweak to get the exact look. ( at least i hope so :)

            alt text

            Do note that the header view (name, size etc) don't care about the margin.
            I did not look into this but I'm sure its also fixable if needed.

            1 Reply Last reply
            0
            • Q Offline
              Q Offline
              Qt.Jo.Ha
              wrote on last edited by
              #6

              @mrjj

              Thank you for answer. Could you send me some code you tested? If the style sheet is applied incorrectly, it cannot be applied.

              mrjjM 1 Reply Last reply
              0
              • Q Qt.Jo.Ha

                @mrjj

                Thank you for answer. Could you send me some code you tested? If the style sheet is applied incorrectly, it cannot be applied.

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @Qt-Jo-Ha

                Hi
                I just placed a treeview on a form, right click and "Change Style sheet"
                then use the

                QAbstractScrollArea {
                border : none; background-color : red; outline :0; padding-left : 24px; padding-right : 0px;
                }
                

                and then i constructor for mainwindow i did

                ui->treeView->viewport()->setStyleSheet("padding-right : 24px;" );

                and also used a file model to have some data.

                Q 1 Reply Last reply
                0
                • mrjjM mrjj

                  @Qt-Jo-Ha

                  Hi
                  I just placed a treeview on a form, right click and "Change Style sheet"
                  then use the

                  QAbstractScrollArea {
                  border : none; background-color : red; outline :0; padding-left : 24px; padding-right : 0px;
                  }
                  

                  and then i constructor for mainwindow i did

                  ui->treeView->viewport()->setStyleSheet("padding-right : 24px;" );

                  and also used a file model to have some data.

                  Q Offline
                  Q Offline
                  Qt.Jo.Ha
                  wrote on last edited by
                  #8

                  @mrjj

                  thank you i try it!!

                  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