Results 1 to 6 of 6

Thread: How to resize again after setFixedSize() ?

  1. #1
    Join Date
    Aug 2011
    Posts
    19
    Thanks
    9
    Qt products
    Qt4

    Default How to resize again after setFixedSize() ?

    Hi,
    I have a project to lock the window size while doing something.
    When the job is finished, the window can be expanded again.

    I try to
    setFixedSize() is called first, and then
    setSizePolicy() is called to set the window resizable again.

    setFixedSize() works, however, setSizePolicy() can not enable
    resizing function again.

    Is resizing after setFixedSize() possible ?

    void MainWindow::startAct()
    {
    this->setFixedSize(this->size());
    QTimer::singleShot(60000, this, SLOT(endAct()));
    }
    void MainWindow::endAct()
    {
    this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); // resizable again
    }

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to resize again after setFixedSize() ?

    I'd suggest to use QLayout::setSizeConstraint() rather than what you are doing.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    chiaminhsu (23rd January 2013)

  4. #3
    Join Date
    Aug 2011
    Posts
    19
    Thanks
    9
    Qt products
    Qt4

    Default Re: How to resize again after setFixedSize() ?

    Thank your. However, QLayout is a virtual class.
    My MainWindow is a simple view window.
    Should I use QBoxLayout or other ?

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to resize again after setFixedSize() ?

    Your MainWindow has a layout installed that can be retrieved with layout(). Call setSizeConstraint() on it asking for fixed size and then back when you want to remove the constraint.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #5
    Join Date
    Aug 2011
    Posts
    19
    Thanks
    9
    Qt products
    Qt4

    Default Re: How to resize again after setFixedSize() ?

    sorry, I rewrite it as the following code. However,
    the window disapeared running setSizeConstraint.
    What's wrong with it ?

    QLayout * layout = this->layout(); // this MainWindow
    layout->setSizeConstraint(QLayout::SetFixedSize);

    * Infact, it's an Qt example called as Tablet.
    * The main window contains a canvas widget only.
    MainWindow::MainWindow(TabletCanvas *canvas) {
    ..
    setCentralWidget(canvas);
    }
    Last edited by chiaminhsu; 23rd January 2013 at 04:48.

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to resize again after setFixedSize() ?

    It is probably because of a proper size policy and size hint of the central widget of the window not being set correctly. The size policy probably allows the widget to be shrunk to 0.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. The following user says thank you to wysota for this useful post:

    chiaminhsu (23rd January 2013)

Similar Threads

  1. setFixedSize() not working
    By stbb24 in forum Qt Programming
    Replies: 2
    Last Post: 4th June 2012, 00:31
  2. Show/Hide height animation with SetFixedSize
    By mnunberg in forum Qt Programming
    Replies: 7
    Last Post: 24th November 2010, 12:11
  3. Resize of main window without setFixedSize
    By ElyBeta in forum Qt Programming
    Replies: 2
    Last Post: 15th July 2010, 16:09
  4. Docking widgets setFixedSize and setBaseSize Problem
    By forrestfsu in forum Qt Programming
    Replies: 2
    Last Post: 16th October 2006, 19:20
  5. setFixedSize
    By raphaelf in forum Qt Programming
    Replies: 3
    Last Post: 22nd February 2006, 12:32

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.