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. adjustSize() or resize() seemingly having to be called twice in a given situation.
Qt 6.11 is out! See what's new in the release blog

adjustSize() or resize() seemingly having to be called twice in a given situation.

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 2 Posters 6.4k 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.
  • worldwidewearyW Offline
    worldwidewearyW Offline
    worldwideweary
    wrote on last edited by
    #1

    Warning: I'm new with Qt, so I may be going about this the wrong way -

    Scenario: UI designer has a frame->horizontalspacer->frame->horizontalspacer-> frame (with button), i.e.:

    0_1527409612740_UI-Frames.png

    The button on the right there is set up so that when pressed, the second frame in the middle is hidden. The intention is so that the button on the right be moved--buttressed against the first frame--and the window resized upon the middle frame's being hidden.

    This works. On initial running, the second frame is set to hidden with an updateSize call based on minimumWidth:

    0_1527410219477_frames2.png

    Now with the button, the pseudo-code: OnClick: if frame is invisible, show it, call window's adjustSize() to update minimumWidth, and then call resize with minimumWidth() and minimumHeight(). This works and results like so (the middle frame was given a minimum size):

    0_1527410356199_frames3.png

    Now the problem is on clicking the button again, the same code for hiding doesn't update the window's minimumWidth appropriately. : Onclick: if frame is visible, hide the frame, call adjust size (here is expected minimumWidth to be updated, yet it isn't upon testing), calling resize afterwards with minimumWIdth() doesn't update the window (but it DOES update the minimumWidth)... the minimumWidth is the same value as the expanded width after adjustSize(). This gives, instead of the first window, something like:

    0_1527410524116_frames4.png

    I can get this to work fine if adjustSize() is called twice before calling resize(), or call resize() twice after one adjustSize(). This seems to be abnormal behavior. Is there something obvious that I'm doing wrong? Not calling a function or something? Any answers are appreciated.

    "The price of freedom is eternal vigilance."

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

      Hi
      Your idea/Design seems ok.
      But without code its hard to guess why window do not contract again.
      You do manually adjust the Window ?

      Maybe you just need to adjust policy
      http://doc.qt.io/qt-5/qsizepolicy.html#details
      to make it want to be as small as possible

      1 Reply Last reply
      0
      • worldwidewearyW Offline
        worldwidewearyW Offline
        worldwideweary
        wrote on last edited by worldwideweary
        #3

        Thanks for trying to help. Yeah, even with SizePolicy set to minimum, it doesn't change the fact that minimumSize() returns a non-updated size after hiding the middle form. No manual adjustment is performed. Yet, again, if updateSize() is called twice after hiding the middle form, the minimumSize() returns the appropriate size and will contract with a resize() call with minimumWidth() and minimumHeight() as arguments. It doesn't contract because the minimumSize() value isn't being updated after one updateSize() call, but it does contract if updateSize() is called twice in a row. Doesn't make any sense. Hoping the 'pseudo-code' should be reasonable enough to understand what's happening.

        "The price of freedom is eternal vigilance."

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

          Hi
          Well when a widget is hidden its resize(ing) might be deferred .
          Try move show() to very to top before rest of code.
          I think its something like that.

          1 Reply Last reply
          0
          • worldwidewearyW Offline
            worldwidewearyW Offline
            worldwideweary
            wrote on last edited by
            #5

            Likewise.
            Calling the window's show(), update(), updateGeometry(), repaint(), all these before anything else after clicking doesn't fix the issue. Merely calling updateSize() twice in a row updates the value got upon calling minimumWidth().

            "The price of freedom is eternal vigilance."

            mrjjM 1 Reply Last reply
            0
            • worldwidewearyW worldwideweary

              Likewise.
              Calling the window's show(), update(), updateGeometry(), repaint(), all these before anything else after clicking doesn't fix the issue. Merely calling updateSize() twice in a row updates the value got upon calling minimumWidth().

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

              @worldwideweary

              Ok. something else then :)

              1 Reply Last reply
              0
              • worldwidewearyW Offline
                worldwidewearyW Offline
                worldwideweary
                wrote on last edited by
                #7

                Anyone else more knowledgeable on the issue willing to share some information?

                "The price of freedom is eternal vigilance."

                mrjjM 1 Reply Last reply
                0
                • worldwidewearyW worldwideweary

                  Anyone else more knowledgeable on the issue willing to share some information?

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

                  @worldwideweary
                  Maybe you should show the actual code ?

                  1 Reply Last reply
                  0
                  • worldwidewearyW Offline
                    worldwidewearyW Offline
                    worldwideweary
                    wrote on last edited by
                    #9

                    It is as the pseudo-code mentioned earlier, but okay:

                    MainWindow::MainWindow(QWidget *parent) :
                    	QMainWindow(parent),
                    	ui(new Ui::MainWindow)
                    {
                    	ui->setupUi(this);
                    	ui->frame_Secondary->setHidden(true);
                    	adjustSize();
                    	resize(minimumWidth(), minimumHeight());
                            // this works fine
                    }
                    
                    void MainWindow::on_pb_ExtendRight_pressed() {
                    	if (ui->frame_Secondary->isHidden()) 
                            {
                    		ui->frame_Secondary->setHidden(false);
                    		ui->pb_ExtendRight->setText(QString("<"));
                    		adjustSize();
                    		resize(minimumWidth(), minimumHeight());
                                    // this works fine
                    	}
                    	else
                    	{
                    		ui->frame_Secondary->setHidden(true);
                    		ui->pb_ExtendRight->setText(QString(">"));
                                    adjustSize();
                    		// This doesn't work unless adjustSize()
                                    // is called twice, or resize() twice
                    	       resize(minimumWidth(), minimumHeight());
                    	}
                    }
                    

                    "The price of freedom is eternal vigilance."

                    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