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. QMainWindow Resize Issue
Qt 6.11 is out! See what's new in the release blog

QMainWindow Resize Issue

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 2.1k Views 2 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.
  • C Offline
    C Offline
    Crag_Hack
    wrote on last edited by Crag_Hack
    #1

    I have a quick question - I have a main window that needs to be resized to its minimum height after hiding some widgets in the window. I have tried

    mainScreen->resize(0,0);
    mainScreen->resize(mainScreen->width(),mainScreen->minimumSizeHint().height());
    

    I have also tried adding these before the resize (in the case of the timer the slot contains the resize code)

    QApplication::processEvents();
    QTimer::singleShot(0,this,SLOT(mainScreenResize()));
    

    None of these resize the window to the new minimum dimensions, instead acting as if the hidden widgets are still there. After hiding the widgets I can manually resize the window to its smaller size but I need this to be automatic. Any ideas? Also I have read the links below and applied their methods without success.

    link 1
    link 2

    Here's the code for hiding widgets and resizing from the backend and also setting up the main window. The resizing code is called from a backend object derived from QWidget (the backend has no widgets I guess that's just the way I set it up in the first place mistakenly) while the main window object (ReplicatorMainScreen) is derived from QMainWindow.

    *update - I tried removing the readWindowSettings() call again no success

    Replicator::Replicator(QWidget *parent) :
        QWidget(parent), wizard(0), mainScreen(0)
    {
        mainScreenSetup();
        mainScreen->setSimpleMode(true);
        //QApplication::processEvents();
        //QTimer::singleShot(0,this,SLOT(mainScreenResize()));
        mainScreen->resize(mainScreen->width(),mainScreen->minimumSizeHint().height());
    }
    
    void Replicator::mainScreenSetup(bool startMinimized, bool minToTray)
    {
        if (!mainScreen)
        {
            mainScreen = new ReplicatorMainScreen;
            mainScreen->show();
            readWindowSettings();
        }
    }
    
    void Replicator::readWindowSettings()
    {
        QSettings settings;
    
        settings.beginGroup("MainWindow");
        if (settings.contains("size"))
            mainScreen->resize(settings.value("size", QSize(400, 400)).toSize());
        if (settings.contains("pos"))
            mainScreen->move(settings.value("pos", QPoint(200, 200)).toPoint());
        settings.endGroup();
    }
    
    void Replicator::mainScreenResize()
    {
        //mainScreen->resize(0,0);
        mainScreen->resize(mainScreen->width(),mainScreen->minimumSizeHint().height());
    }
    
    void ReplicatorMainScreen::setSimpleMode(bool enabled)
    {
        ui->newJobButton->setVisible(!enabled);
    ...
    }
    

    Thanks for the help!

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

      Hi,

      You might get some ideas here.

      Hope it helps

      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
      0
      • C Offline
        C Offline
        Crag_Hack
        wrote on last edited by Crag_Hack
        #3

        Ha I found a cheap hack ...

        QTimer::singleShot(100,this,SLOT(mainScreenResize()));
        

        good enough for me you can see the resize take place but it's no deal breaker

        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