How to emit resize event intentionally?



  • I´m in a class that creates all custom widgets. But the main window doesn´t emit the resize at the beginning of the app. I would like to generate the event by hand, or make it happen somehow so it positions the widgets correctly at the beginning.

    How do i do it?. I don´t know the size of the window or anything else, so the Event i emit i don´t know what should be there.

    Thanks.



  • If you are referring to the QMainWindow, it is inherited from the QWidget.
    You can override the void QWidget::resizeEvent(QResizeEvent *event) and send a signal out of it:

    @
    void MyMainWindow::resizeEvent (QResizeEvent *event)
    {
    // My signal
    emit mySizeChanged(event->size());
    }
    @



  • Resizing it will sent the event.

    this->resize(this->geometry().width(), this->geometry().height());



  • It does not because it is not resized. What do you want to achieve exactly?



  • Do not cheat yourself. You should use layouts. If you use a QMainWindow the best practice will be to use a QMdiArea for handling internal windows. If you use a simple QWidget, just apply one of the layouts (for example QVBoxLayout) and you will be sure that everything will be look perfect.
    Using signals of resizes for widgets positioning looks very strange.
    If the layouts don't work for it, probably you did something wrong.


Log in to reply
 

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