[SOLVED] QDialog - overwriting the native "Expand" event



  • I would like to reimplement what the native "Expand" button does inside a QDialog
    Instead of showing Maximized, I would show the dialog Fullscreen.

    First, I have to catch the event to reimplement it, but not sure which one I have to reimplement
    I tried :
    @void resizeEvent(QResizeEvent *event);@

    that comes from QWidget but this event throw all resize not just the "expand" event.

    If you know a way to do it, would be nice to share, Thank you!



  • Can you check QEvent::WindowStateChange ?



  • This seems to work :

    However I would like to catch the click on the button Expand before the Expand button cause the event, because now i'm a bit late and need to react to what just happened, I would like to overwrite the behavior of the Expand button, if that is ever possible.

    @ void WorkoutDialog::changeEvent(QEvent *event) {

     qDebug() << "changeEvent-------------------" << event << "type" << event->type();
    
     if (event->type() == QEvent::WindowStateChange) {
         qDebug() << "WINDOW CHANGE";
     }
    

    }@



  • You can try this.

    @void Widget::changeEvent(QEvent *event)
    {
    if (event->type() == QEvent::WindowStateChange)
    if(windowState().testFlag(Qt::WindowMaximized) == true)
    qDebug() << "Maximize " << endl;
    QWidget::changeEvent(event);
    }@



  • You should use eventFilter to filter out the required events before passing or try re-implementing event() itself and handle appropriately.

    bool Widget::event(QEvent *evt){
    if (evt->type() == QEvent::WindowStateChange) {
    qDebug() << "WIndow changed =" << evt->type() << endl;
    if(windowState().testFlag(Qt::WindowMaximized) == true)
    qDebug() << "Maximize. I'm handling it. " << endl;
    return true;
    }
    return QWidget::event(evt);
    }



  • With this:

    @void WorkoutDialog::changeEvent(QEvent *event) {

    if (event->type() == QEvent::WindowStateChange) {
        if(windowState().testFlag(Qt::WindowMaximized) == true) {
            qDebug() << "Maximize " << endl;
            return;   // Do not maximize, exit and cancel event
        }
    }
    else {
        QWidget::changeEvent(event);
    }
    

    }@

    The Maximize button still works, I would like to disable it's original functionality and put a new one, possible? Thanks for the help!

    [Edit: oh yes I completely forgot about EventFilter, will try this approach and post result]



  • It seems there is no way to cancel the original native event "expand"

    With the code bellow, I can see when a Expand occur, but have no way to cancel it, right? I could call a fullscreen after the expand, but it seems bad, any other way? thank you!

    @bool WorkoutDialog::eventFilter(QObject *watched, QEvent *event) {

     Q_UNUSED(watched);
    
    qDebug() << "watched object" << watched << "event:" << event << "eventType" << event->type();
    
    
    if(event->type() == QEvent::WindowStateChange)
    {
        qDebug() << "WindowStateChange!!!!!!!!!!!!!!!!!!!!!!!!!!!****************";
        if(windowState().testFlag(Qt::WindowMaximized) == true) {
            qDebug() << "Maximize " << endl;
            this->showFullScreen();
            return true;
        }
    
    }
    
    return false;@


  • So far it works with this code :

    constructor :

    @ ui->setupUi(this);
    Qt::WindowFlags flags = Qt::Window;
    this->setWindowFlags(flags);

    installEventFilter(this);@
    

    eventFilter:

    @bool WorkoutDialog::eventFilter(QObject *watched, QEvent *event) {

    Q_UNUSED(watched);
    
    qDebug() << "watched object" << watched << "event:" << event << "eventType" << event->type();
    
    
    if(event->type() == QEvent::WindowStateChange)
    {
        qDebug() << "WindowStateChange!!!!!!!!!!!!!!!!!!!!!!!!!!!****************";
        if(windowState().testFlag(Qt::WindowMaximized) == true) {
            qDebug() << "Maximize " << endl;
            this->showFullScreen();
            return true;
        }
    
    }
    return false;
    

    }@


Log in to reply
 

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