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. QGridLayout - Fixed Number of Rows and Columns
Forum Updated to NodeBB v4.3 + New Features

QGridLayout - Fixed Number of Rows and Columns

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 3 Posters 7.6k 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.
  • webzoidW Offline
    webzoidW Offline
    webzoid
    wrote on last edited by
    #1

    Is there any way to force a QGridLayout to adopt a fixed number of rows and columns of equal size?

    I'm looking for a way of dragging a QWidget onto the layout, but then allowing it to be resized while snapping to the rows, columns to maintain a regular size.

    raven-worxR 1 Reply Last reply
    0
    • webzoidW webzoid

      Is there any way to force a QGridLayout to adopt a fixed number of rows and columns of equal size?

      I'm looking for a way of dragging a QWidget onto the layout, but then allowing it to be resized while snapping to the rows, columns to maintain a regular size.

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

      @webzoid
      You could pre-insert fixed sized plain widgets into the grid layout. Those widgets then accept the drop events and place the widget inside them.
      I think thats the easiest solution without much "hacking".

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

        @raven-worx Thanks for your quick reply.

        This sounds ok so far, but, what would happen when I want to resize a widget to cover, say, 3 columns and 2 rows? What would happen to those pre-inserted widgets?

        I don't mind having to do a bit of hacking - maybe a QWidget or custom QLayout to do the layout logic would be a more elegant solution?

        raven-worxR 1 Reply Last reply
        0
        • webzoidW webzoid

          @raven-worx Thanks for your quick reply.

          This sounds ok so far, but, what would happen when I want to resize a widget to cover, say, 3 columns and 2 rows? What would happen to those pre-inserted widgets?

          I don't mind having to do a bit of hacking - maybe a QWidget or custom QLayout to do the layout logic would be a more elegant solution?

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

          @webzoid said in QGridLayout - Fixed Number of Rows and Columns:

          This sounds ok so far, but, what would happen when I want to resize a widget to cover, say, 3 columns and 2 rows? What would happen to those pre-inserted widgets?

          I can't tell you straight from head, but just evaluate it with a small example. If the behavior is not as desired you will have to go with a custom layout. Which might be hard work though.

          --- 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
          0
          • webzoidW Offline
            webzoidW Offline
            webzoid
            wrote on last edited by
            #5

            @raven-worx Sorry, I didn't mean to put you on the spot... haha.

            I've actually been thinking about a custom layout and that it may not be so difficult. If I could specify a number of rows/columns then I can calculate height/width of each cell so that when a widget is resized, I can dynamically compute its size based on its column/row spans.

            I'm sure its not a trivial exercise mind but it seems a cute way of doing it. Google searches tell me that plenty of people have tried before but ultimately failed - maybe this is my time to shine!

            raven-worxR 1 Reply Last reply
            0
            • webzoidW webzoid

              @raven-worx Sorry, I didn't mean to put you on the spot... haha.

              I've actually been thinking about a custom layout and that it may not be so difficult. If I could specify a number of rows/columns then I can calculate height/width of each cell so that when a widget is resized, I can dynamically compute its size based on its column/row spans.

              I'm sure its not a trivial exercise mind but it seems a cute way of doing it. Google searches tell me that plenty of people have tried before but ultimately failed - maybe this is my time to shine!

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

              @webzoid
              :)
              Difficulty is relative ;)

              --- 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
              0
              • webzoidW Offline
                webzoidW Offline
                webzoid
                wrote on last edited by
                #7

                Ok, so I'm mocking something up using a QTableWidget which, surprisingly, seems to be allowing me to do what I want so far. I can set up a fixed number of rows/columns and I can add widgets to a cell which then can be spanned across cols/rows.

                Drag and drop seems to be working nicely, just need to figure out the runtime widget resizing and spanning...

                1 Reply Last reply
                1
                • webzoidW Offline
                  webzoidW Offline
                  webzoid
                  wrote on last edited by
                  #8

                  Is there any way of preventing a QWidget which has been bound to a QTableWidget cell (using the setCellWidget function) from being destroyed when calling removeCellWidget?

                  I'm wanting to move a QWidget to another cell, but, when dragging it to another cell (and subsequently calling setCellWidget), the "old" cell still holds a pointer to the widget even though it has been moved to another cell.

                  1 Reply Last reply
                  0
                  • webzoidW Offline
                    webzoidW Offline
                    webzoid
                    wrote on last edited by
                    #9

                    Ok, so using a blood-and-thunder method, I've managed to achieve what I want but basically, its a crappy solution so I'm going to need to look at another way of doing things.

                    The QTableWidget is just far too slow when large numbers of rows/columns are used.

                    1 Reply Last reply
                    0
                    • VRoninV Offline
                      VRoninV Offline
                      VRonin
                      wrote on last edited by
                      #10

                      setCellWidget is notoriously painfully slow. It's not a problem of QTableWidget
                      Are the widget the same type in all cells?

                      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                      ~Napoleon Bonaparte

                      On a crusade to banish setIndexWidget() from the holy land of Qt

                      webzoidW 1 Reply Last reply
                      0
                      • VRoninV VRonin

                        setCellWidget is notoriously painfully slow. It's not a problem of QTableWidget
                        Are the widget the same type in all cells?

                        webzoidW Offline
                        webzoidW Offline
                        webzoid
                        wrote on last edited by
                        #11

                        @VRonin Yeah, I appreciate that its an issue with the underlying implementation - my fumbling has had be digging into the QAbstractItemView class and implementing my own setIndexWidget function in a custom QTableView class.

                        Ultimately, the widgets dropped into the cells will have the same base class but the derivatives will be very different.

                        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