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 weird behavior on column click
Forum Updated to NodeBB v4.3 + New Features

qtreeview weird behavior on column click

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 931 Views 3 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.
  • U Offline
    U Offline
    user4592357
    wrote on last edited by
    #1

    i have an object of QTreeView subclass, and it has 2 columns. when the first column is fully visible and the second one is partially visible, when i click on an item in second column, the view scrolls horizontally (i just to show the whole second column). how can i disable this?
    and if i can't disable it, how can i make the second column fixed width? so when the view is widened, only the first column is widened and the second one just stays the same width.

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

      Hi,

      You can modify the resizing behaviour of a column using QHeadView::setSectionResizeMode

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

      U 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        You can modify the resizing behaviour of a column using QHeadView::setSectionResizeMode

        U Offline
        U Offline
        user4592357
        wrote on last edited by
        #3

        @SGaist
        i know about that. when i set it, the column definitely has a fixed size. the problem is that when i resize the view, the second column doesn't resize but a space is added after it (something like a third column). but that's not what i want. i need the first column widened when the view is widened, and the second column to stay fixed width (the second column should always touch right side of the view, with section resize option the newly added space doesn't let that happen)

        also, i don't know how to set the actual width i want it to be.

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

          Then why not set QHeaderView::Stretch on the first column ?

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

          1 Reply Last reply
          2
          • U user4592357

            @SGaist
            i know about that. when i set it, the column definitely has a fixed size. the problem is that when i resize the view, the second column doesn't resize but a space is added after it (something like a third column). but that's not what i want. i need the first column widened when the view is widened, and the second column to stay fixed width (the second column should always touch right side of the view, with section resize option the newly added space doesn't let that happen)

            also, i don't know how to set the actual width i want it to be.

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

            @user4592357

            • also, i don't know how to set the actual width i want it to be.
              You mean ?
              http://doc.qt.io/qt-5/qheaderview.html#resizeSection
            1 Reply Last reply
            2
            • U Offline
              U Offline
              user4592357
              wrote on last edited by user4592357
              #6

              @SGaist
              that didn't work because column 0 didn't exist yet when i set the resize mode.
              EDIT: i also needed to set QHeaderView::Fixed for the second column, and it worked.

              @mrjj
              that had no effect on column width.
              EDIT: setDefaultSectionSize() seemed to do the trick.

              reference answer used: https://stackoverflow.com/questions/47769122/qtreeview-with-fixed-column-widths

              1 Reply Last reply
              0
              • U Offline
                U Offline
                user4592357
                wrote on last edited by user4592357
                #7
                This post is deleted!
                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