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 2 Column, when Widget hide, auto resize
Forum Updated to NodeBB v4.3 + New Features

QGridlayout 2 Column, when Widget hide, auto resize

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

    Hello!
    I have widgets in QGridLayout.
    QGridlayout's column size 2, row size variable.
    When i hide 2.button; the 3.'button not going to 2.'button's place. Is there anyway to do this automaticly?
    I don't want to removeWidget because i am trying to do filtering, i have widgets, i can show and hide. When i remove widget; filtering system will not work.
    So Is there anyway to take place of hidding widget's?
    Thank you.
    question.png

    jsulmJ 1 Reply Last reply
    0
    • EmrecpE Emrecp

      Hello!
      I have widgets in QGridLayout.
      QGridlayout's column size 2, row size variable.
      When i hide 2.button; the 3.'button not going to 2.'button's place. Is there anyway to do this automaticly?
      I don't want to removeWidget because i am trying to do filtering, i have widgets, i can show and hide. When i remove widget; filtering system will not work.
      So Is there anyway to take place of hidding widget's?
      Thank you.
      question.png

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Emrecp said in QGridlayout 2 Column, when Widget hide, auto resize:

      Is there anyway to do this automaticly?

      Not automatically.
      "I don't want to removeWidget because i am trying to do filtering" - I don't understand this. What filtering do you mean and how is it going to work if you put 3.'button where 2.'button was before?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      EmrecpE 1 Reply Last reply
      0
      • jsulmJ jsulm

        @Emrecp said in QGridlayout 2 Column, when Widget hide, auto resize:

        Is there anyway to do this automaticly?

        Not automatically.
        "I don't want to removeWidget because i am trying to do filtering" - I don't understand this. What filtering do you mean and how is it going to work if you put 3.'button where 2.'button was before?

        EmrecpE Offline
        EmrecpE Offline
        Emrecp
        wrote on last edited by
        #3

        @jsulm Loop in QGridLayout, checking widget's variable, if search QTextEdit's text in widget's variable then i will show widget else i am hiding widget.
        I don't want to removewidget because when search QTextEdit is empty; all widgets must be showen.
        Thanks

        jsulmJ JonBJ 2 Replies Last reply
        0
        • EmrecpE Emrecp

          @jsulm Loop in QGridLayout, checking widget's variable, if search QTextEdit's text in widget's variable then i will show widget else i am hiding widget.
          I don't want to removewidget because when search QTextEdit is empty; all widgets must be showen.
          Thanks

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Emrecp said in QGridlayout 2 Column, when Widget hide, auto resize:

          I don't want to removewidget because when search QTextEdit is empty; all widgets must be showen.

          Then show all of them if text edit is empty - move every widget to the position where it should be if all widgets are shown.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          EmrecpE 1 Reply Last reply
          2
          • EmrecpE Emrecp

            @jsulm Loop in QGridLayout, checking widget's variable, if search QTextEdit's text in widget's variable then i will show widget else i am hiding widget.
            I don't want to removewidget because when search QTextEdit is empty; all widgets must be showen.
            Thanks

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

            @Emrecp
            I too am somewhat lost on what you want to achieve why.

            But as @jsulm says: if you have a QGridLayout, and if you want to hide one of the widgets, and if you then want all the other widgets to move left/up to close up the unoccupied space: then Qt grid won't do that for you, it is your job to move all the necessary widgets around to their new positions. Note how

            void QGridLayout::addWidget(QWidget *widget, int row, int column, Qt::Alignment alignment = Qt::Alignment())
            

            allows you to position widgets at specified row/column, you would need to removeWidget() from its current position and then call that to move it to new position. When hidden widget becomes visible again, you would need to shuffle the others back to original positions.

            If you are willing to give up on your exact grid positioning, what you may really want is what I have used in the past. When I had a bunch of filters to show the user, and some of them needed to be hidden/shown from time to time, what I wanted was for them to move around to close up the gap. Qt does not offer this as a layout, but I found the Flow Layout Example. You would have to copy all that code. That gives you a layout where items are places left-to-right, and when they reach the width of the flow panel it grows vertically and they are floated down to the next line below. You don't get an exact "grid" layout, but you get no gaps and it takes up the minimum width/height for the items. Quite a bit of work, but up to you....

            1 Reply Last reply
            1
            • jsulmJ jsulm

              @Emrecp said in QGridlayout 2 Column, when Widget hide, auto resize:

              I don't want to removewidget because when search QTextEdit is empty; all widgets must be showen.

              Then show all of them if text edit is empty - move every widget to the position where it should be if all widgets are shown.

              EmrecpE Offline
              EmrecpE Offline
              Emrecp
              wrote on last edited by Emrecp
              #6

              @jsulm @JonB Thanks for comments.
              I solved with creating another QGridLayout, when search text edit's textChanged, clearing all widgets in first QGridLayout; then I am looping in second QGridLayout (all widgets here), if it's compatible with variable then i am adding to first QGridLayout. Then i show first QGridLayout.

              I was hoping QGridLayout do this automaticly.

              Here is code if someone needs

                          # CLEAR WIDGETs
                          for i in range(1, self.vbox.count()):
                              if self.vbox.itemAt(i) != None and self.vbox.itemAt(i).widget()!=None:
                                  self.vbox.itemAt(i).widget().hide()
                          # < CLEAR WIDGETs >
                          INDEX = 1
                          for i in range( self.QGRID_ALL_WIDGETS.count()):
                              if self.QGRID_ALL_WIDGETS.itemAt(i) != None and self.QGRID_ALL_WIDGETS.itemAt(i).widget() != None:
                                  if (str(Ad).lower() in str(SearchText).lower()): #  Ad is my special variable
                                      wid.show()
                                      self.vbox.addWidget(wid, math.ceil(INDEX / 2), (INDEX - 1) % 2, 1, 1)
                                      INDEX += 1
                                  else:
                                      wid.hide()
              
              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