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. resize by clicking the column edges
Forum Updated to NodeBB v4.3 + New Features

resize by clicking the column edges

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 404 Views
  • 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.
  • NevezN Offline
    NevezN Offline
    Nevez
    wrote on last edited by
    #1

    e8e19c12-f08b-44a7-8926-5b14dd03370a-image.png

    hello, there is a tableview as in the picture. I want to adjust the width of the column by clicking and dragging the edges of the column on this view. (not by clicking on the header).

    How can I do that ? any idea ?
    Thanks.

    Christian EhrlicherC 1 Reply Last reply
    0
    • NevezN Nevez

      e8e19c12-f08b-44a7-8926-5b14dd03370a-image.png

      hello, there is a tableview as in the picture. I want to adjust the width of the column by clicking and dragging the edges of the column on this view. (not by clicking on the header).

      How can I do that ? any idea ?
      Thanks.

      Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Nevez said in resize by clicking the column edges:

      How can I do that ? any idea ?

      Since it's not supported out-of the box you have to derive from QTableView and implement it by yourself.

      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
      • NevezN Offline
        NevezN Offline
        Nevez
        wrote on last edited by
        #3

        I understood. So which functions should I focus on exactly?
        can you explain a little bit

        JonBJ 1 Reply Last reply
        0
        • NevezN Nevez

          I understood. So which functions should I focus on exactly?
          can you explain a little bit

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @Nevez
          It seems to me that if you won't use the existing header-only drag-resize facility of QHeaderView you are going to have to do the whole thing yourself. You will need to:

          • Recognize a mouse-down anywhere over the QTableView (or its viewPort()).
          • Look at its horizontal position to determine whether it is "close enough" to an existing column divider to count as having moused-down on a column "edge". This is complex, allowing for viewport, "visual indexes", whether the table view has been scrolled horizontally, etc.
          • Do some kind of "drag" operation, showing a divider line.
          • Figure out the final, new width you want to adjust the column to.

          You could take a a look e.g. https://codebrowser.dev/qt5/qtbase/src/widgets/itemviews/qheaderview.cpp.html to see the kind of work it does. The code at void QHeaderView::mousePressEvent(QMouseEvent *e) shows how that starts a mouse-down operation, it includes

          int handle = d->sectionHandleAt(pos);
          ...
          } else if (sectionResizeMode(handle) == Interactive) {
          

          which is the resize-columns case.

          Seems like an enormous amount of work, with all it has to deal with! I certainly would not want to do so :)

          Maybe you could do something like recognise when your mouse down is over a column divider and then somehow forward it to the QHeaderView at the corresponding horizontal place, so that you then get it to handle the drag-resize for you, but that may be messy/not easy.

          1 Reply Last reply
          0
          • NevezN Offline
            NevezN Offline
            Nevez
            wrote on last edited by
            #5

            Thanks for your comment. I guess I'll have to give up on this method.

            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