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. [SOLVED] QDialog - overwriting the native "Expand" event
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 2.6k Views 1 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.
  • M Offline
    M Offline
    maximus
    wrote on last edited by
    #1

    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!


    Free Indoor Cycling Software - https://maximumtrainer.com

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Can you check QEvent::WindowStateChange ?

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • M Offline
        M Offline
        maximus
        wrote on last edited by
        #3

        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";
         }
        

        }@


        Free Indoor Cycling Software - https://maximumtrainer.com

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          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);
          }@

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply
          0
          • dheerendraD Offline
            dheerendraD Offline
            dheerendra
            Qt Champions 2022
            wrote on last edited by
            #5

            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);
            }

            Dheerendra
            @Community Service
            Certified Qt Specialist
            http://www.pthinks.com

            1 Reply Last reply
            0
            • M Offline
              M Offline
              maximus
              wrote on last edited by
              #6

              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]


              Free Indoor Cycling Software - https://maximumtrainer.com

              1 Reply Last reply
              0
              • M Offline
                M Offline
                maximus
                wrote on last edited by
                #7

                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;@
                

                Free Indoor Cycling Software - https://maximumtrainer.com

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  maximus
                  wrote on last edited by
                  #8

                  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;
                  

                  }@


                  Free Indoor Cycling Software - https://maximumtrainer.com

                  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