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

Missing ScrollBar

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 834 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.
  • ModelTechM Offline
    ModelTechM Offline
    ModelTech
    wrote on last edited by
    #1

    I have created a QTreeListWidget that is part of my Layout. The width of the QTreeListWidget (or actually its encapsulating widget) is fixed to 200. I would expect a horizontal scrollbar to appear in case the text for any QTreeListWidgetItems is too long to be fully visible. However, I noticed that the width of the text is in fact not taken into account at all. The scrollbar only appears in case the selectors or icons come beyond the width of the QTreeListWidget. Any ideas how I can get a scrollbar in case the text does not fit anymore (as in the screenshot below)?

    Missing ScrollBar

    raven-worxR 1 Reply Last reply
    0
    • ModelTechM ModelTech

      I have created a QTreeListWidget that is part of my Layout. The width of the QTreeListWidget (or actually its encapsulating widget) is fixed to 200. I would expect a horizontal scrollbar to appear in case the text for any QTreeListWidgetItems is too long to be fully visible. However, I noticed that the width of the text is in fact not taken into account at all. The scrollbar only appears in case the selectors or icons come beyond the width of the QTreeListWidget. Any ideas how I can get a scrollbar in case the text does not fit anymore (as in the screenshot below)?

      Missing ScrollBar

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @ModelTech
      check the horizontal scrollbar policy property of the tree widget. It should be either Qt::ScrollBarAsNeeded or Qt::ScrollBarAlwaysOn.

      If that's the case you can try:

      treeWidget->header()->setResizeMode( QHeaderView::ResizeToContents );
      

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      3
      • ModelTechM Offline
        ModelTechM Offline
        ModelTech
        wrote on last edited by ModelTech
        #3

        Thanks. I tried the following (where Explorer is my QTreeWidget) as there is no setResizeMode function (I am using Qt 5.12.0). Unfortunately, this alone did not give the desired effect.

            Explorer->setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAsNeeded);
            Explorer->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
        

        If I set the scrollbar policy to AlwaysOn, the scrollbar sows that there is nothing to scroll. So, I used setColumnCount to set the number of columns to 2 instead of the default of 1. Together with the above, that solved the problem. As I do not really understand the column part: should the number of columns be equal to the depth of the tree?

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          The default elide mode for the views is 'ElideRight': https://doc.qt.io/qt-5/qabstractitemview.html#textElideMode-prop

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          2
          • ModelTechM Offline
            ModelTechM Offline
            ModelTech
            wrote on last edited by
            #5

            Interesting, I needed that for another part of my app. Thanks!
            However, without setting the number of columns to 2 it has however no effect...

            1 Reply Last reply
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @ModelTech said in Missing ScrollBar:

              However, without setting the number of columns to 2 it has however no effect...

              The scrollbar is show, after you e.g. called resizeColumnToContents(). Just tested it in the designer

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              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