Automatic resizing of window

  • Hello everybody. Here is my problem:

    I am developing a Qt app using QTEditor. The app needs to resize itself at runtime, depending on how many graphical elements are attached to it. I thought of handling this through a shrink() method in the main window:

    @class MainWindow : public QMainWindow {

    private slots:
    void shrink() {
    // Also tried: resize(0, 0);

    Calling shrink() can however be quite hit and miss. Sometimes, the window does get resized to the intended, minimal size. Other times, it keeps its original size, and I need to call shrink() again to get the intended outcome. It is suggested "here": that this is a timing issue. The proposed solution is to call shrink() throgh QTimer::singleShot, such as:

    @QTimer::singleShot(0, this, SLOT(shrink());@

    However, this has no effect in my case. Even throwing in a call to QtApplication::processEvents() has no effect.

    Are you aware of any other solution ?

    Thank you.

  • Moderators

    welcome to devnet

    Is the slot shrink() activated by the singleShot?
    Since there might be timing issue, you might want to give a bit more time before firing the shot.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.