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. I want to change the size of a window when press the minimize button instead of minimizing it .
Forum Updated to NodeBB v4.3 + New Features

I want to change the size of a window when press the minimize button instead of minimizing it .

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 4.5k 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.
  • L Offline
    L Offline
    lexdene
    wrote on last edited by
    #1

    @MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    void MainWindow::changeEvent ( QEvent * event)
    {
    if(windowState() & Qt::WindowMinimized)
    {
    setWindowState(windowState() & ~Qt::WindowMinimized);
    resize(size()*0.5);
    }
    }
    @
    But this code doesn't run as I supposed .
    After I press the minimize button ,
    the window minimizes before its size has been changed ,
    and then appears with a shortened size .

    What should I do if I want to change the size of a window when press the minimize button instead of minimizing it .

    enviroment :
    Qt 4.7.2
    ubuntu 11.04

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      You have to react on the OS system events, e.g. on windows, you overwrite
      winEvent and react on WM_SYSTEM I think...

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #3

        Be aware that you miserably break the user's expectations by fiddling around with those things. I personally would ditch such an application to the trash bin immediately.

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          I think you should accept the event in your code, after it has done your stuff. If you don't do that, the event is passed further down the event loop, and then the default handler minimizes the window. But if you accept, processing of this particular event stops:

          @
          event->accept();
          @

          (Z(:^

          1 Reply Last reply
          0
          • G Offline
            G Offline
            giesbert
            wrote on last edited by
            #5

            No,
            the event is send, when the window is minimized, not to minimize it.

            bq. The window's state (minimized, maximized or full-screen) has changed (QWindowStateChangeEvent).

            So IMHO using changeEvent is too late.

            On X11, internally for minimizing a window, the following event is send by QWidget:

            @
            XEvent e;
            e.xclient.type = ClientMessage;
            e.xclient.message_type = ATOM(WM_CHANGE_STATE);
            e.xclient.display = X11->display;
            e.xclient.window = data->winid;
            e.xclient.format = 32;
            e.xclient.data.l[0] = IconicState;
            e.xclient.data.l[1] = 0;
            e.xclient.data.l[2] = 0;
            e.xclient.data.l[3] = 0;
            e.xclient.data.l[4] = 0;
            XSendEvent(X11->display,
            RootWindow(X11->display,d->xinfo.screen()),
            False, (SubstructureNotifyMask|SubstructureRedirectMask), &e);

            ...
            data->window_state = newstate;

            if (needShow)
                show();
            
            if (newstate & Qt::WindowActive)
                activateWindow();
            
            QWindowStateChangeEvent e(oldstate);
            QApplication::sendEvent(this, &e);
            

            @

            as you can see, the stateChange is the last thing.

            You could overwrite "QWidget::x11Event":http://doc.qt.nokia.com/4.7/qwidget.html#x11Event to catch the minimize event and then you should be able to stop from propagating it.

            Nokia Certified Qt Specialist.
            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

            1 Reply Last reply
            0
            • L Offline
              L Offline
              lexdene
              wrote on last edited by
              #6

              @#include "mainwindow.h"
              #include "ui_mainwindow.h"

              #include <QDebug>
              #include <qwindowdefs.h>
              #include <Xlib.h>

              MainWindow::MainWindow(QWidget *parent) :
              QMainWindow(parent),
              ui(new Ui::MainWindow)
              {
              ui->setupUi(this);
              }

              MainWindow::~MainWindow()
              {
              delete ui;
              }

              bool MainWindow::x11Event ( XEvent * e )
              {
              if(e->xclient.type == ClientMessage )
              {
              qDebug()<<e->xclient.type
              <<e->xclient.message_type
              <<e->xclient.display
              <<e->xclient.window
              <<e->xclient.format
              <<e->xclient.data.l[0]
              <<e->xclient.data.l[1]
              <<e->xclient.data.l[2]
              <<e->xclient.data.l[3]
              <<e->xclient.data.l[4];
              }
              return false;
              }@

              code like this .
              Add these in .pro file:
              @INCLUDEPATH += /usr/include/X11
              LIBS += -L/usr/X11/lib -lX11@

              But I see nothing output before it minimized .

              Is my code right ?
              Or should I catch the minimize event somewhere else ?

              thank you .

              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