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] Cast event when window size is changed

[SOLVED] Cast event when window size is changed

Scheduled Pinned Locked Moved General and Desktop
maximize
14 Posts 2 Posters 6.8k Views
  • 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.
  • B Offline
    B Offline
    Bremenpl
    wrote on 16 Apr 2015, 06:34 last edited by Bremenpl
    #1

    Hello there,
    I was wondering either it is possible to cast an event when I press maximize button in my main window, or resize it? I was trying to find some refference about this but with no luck. I Would aprichiate any help!

    lprzenioslo.zut.edu.pl

    P 1 Reply Last reply 16 Apr 2015, 06:54
    0
    • B Bremenpl
      16 Apr 2015, 06:34

      Hello there,
      I was wondering either it is possible to cast an event when I press maximize button in my main window, or resize it? I was trying to find some refference about this but with no luck. I Would aprichiate any help!

      P Offline
      P Offline
      p3c0
      Moderators
      wrote on 16 Apr 2015, 06:54 last edited by
      #2

      @Bremenpl Re-implement resizeEvent inside the mainwindow and cast events there.

      157

      B 1 Reply Last reply 16 Apr 2015, 07:33
      0
      • P p3c0
        16 Apr 2015, 06:54

        @Bremenpl Re-implement resizeEvent inside the mainwindow and cast events there.

        B Offline
        B Offline
        Bremenpl
        wrote on 16 Apr 2015, 07:33 last edited by p3c0
        #3

        @p3c0
        Could you please show me the proper way of doing this? So far I have added the method in my .h class:

        void resizeEvent(QResizeEvent * /* event */);

        And in .cpp:

        void MainWindow::resizeEvent(QResizeEvent * /* event */)
        {
            moveUndoView();
        }
        

        The moveUndoView() is :

        void MainWindow::moveUndoView()
        {
            QPoint p = pos();
        
            p += QPoint(width(), height());
            p -= QPoint(undoView->width(), undoView->height());
            undoView->move(p);
        }
        

        I am getting segmentation fault when running this code. Any hints? The segfault occurs at line:
        p -= QPoint(undoView->width(), undoView->height());

        For some reason I cannot acces undoView Object from this scope.

        lprzenioslo.zut.edu.pl

        P 1 Reply Last reply 16 Apr 2015, 07:56
        0
        • B Bremenpl
          16 Apr 2015, 07:33

          @p3c0
          Could you please show me the proper way of doing this? So far I have added the method in my .h class:

          void resizeEvent(QResizeEvent * /* event */);

          And in .cpp:

          void MainWindow::resizeEvent(QResizeEvent * /* event */)
          {
              moveUndoView();
          }
          

          The moveUndoView() is :

          void MainWindow::moveUndoView()
          {
              QPoint p = pos();
          
              p += QPoint(width(), height());
              p -= QPoint(undoView->width(), undoView->height());
              undoView->move(p);
          }
          

          I am getting segmentation fault when running this code. Any hints? The segfault occurs at line:
          p -= QPoint(undoView->width(), undoView->height());

          For some reason I cannot acces undoView Object from this scope.

          P Offline
          P Offline
          p3c0
          Moderators
          wrote on 16 Apr 2015, 07:56 last edited by
          #4

          @Bremenpl With cast an event what do you mean by it ? What are you trying to achieve ? Can you post more details ? Looking at code it seems you are trying to move some widget.
          Also please use ``` (3 backticks) for posting code blocks.

          157

          B 1 Reply Last reply 16 Apr 2015, 08:00
          0
          • P p3c0
            16 Apr 2015, 07:56

            @Bremenpl With cast an event what do you mean by it ? What are you trying to achieve ? Can you post more details ? Looking at code it seems you are trying to move some widget.
            Also please use ``` (3 backticks) for posting code blocks.

            B Offline
            B Offline
            Bremenpl
            wrote on 16 Apr 2015, 08:00 last edited by
            #5

            @p3c0
            Sorry for the formating. yes, I am trying to move a widget (UndoView) when the MainWindow is resized.

            lprzenioslo.zut.edu.pl

            P 1 Reply Last reply 16 Apr 2015, 08:49
            0
            • B Bremenpl
              16 Apr 2015, 08:00

              @p3c0
              Sorry for the formating. yes, I am trying to move a widget (UndoView) when the MainWindow is resized.

              P Offline
              P Offline
              p3c0
              Moderators
              wrote on 16 Apr 2015, 08:49 last edited by
              #6

              @Bremenpl And what is UndoView ? What type ?

              157

              B 1 Reply Last reply 16 Apr 2015, 08:49
              0
              • P p3c0
                16 Apr 2015, 08:49

                @Bremenpl And what is UndoView ? What type ?

                B Offline
                B Offline
                Bremenpl
                wrote on 16 Apr 2015, 08:49 last edited by
                #7

                @p3c0
                Its something I am trying to implement from here http://docs.knobbits.org/qt4/tools-undoframework.html#mainwindow-class-definition

                lprzenioslo.zut.edu.pl

                P 1 Reply Last reply 16 Apr 2015, 09:01
                0
                • B Bremenpl
                  16 Apr 2015, 08:49

                  @p3c0
                  Its something I am trying to implement from here http://docs.knobbits.org/qt4/tools-undoframework.html#mainwindow-class-definition

                  P Offline
                  P Offline
                  p3c0
                  Moderators
                  wrote on 16 Apr 2015, 09:01 last edited by
                  #8

                  @Bremenpl If you want to some it in accordance with the MainWindow that you can get width and height from QResizeEvent and move the QUndoView. Something like

                  void MainWindow::resizeEvent(QResizeEvent *e)
                  {
                      undoView->move(e->size().width(),undoView->y());
                  }
                  

                  This will move undoView on x axis as mainwindow resize. Add some more calculation as per your requirement.

                  157

                  B 1 Reply Last reply 16 Apr 2015, 09:05
                  0
                  • P p3c0
                    16 Apr 2015, 09:01

                    @Bremenpl If you want to some it in accordance with the MainWindow that you can get width and height from QResizeEvent and move the QUndoView. Something like

                    void MainWindow::resizeEvent(QResizeEvent *e)
                    {
                        undoView->move(e->size().width(),undoView->y());
                    }
                    

                    This will move undoView on x axis as mainwindow resize. Add some more calculation as per your requirement.

                    B Offline
                    B Offline
                    Bremenpl
                    wrote on 16 Apr 2015, 09:05 last edited by Bremenpl
                    #9

                    @p3c0
                    Accesing undoView in resizeEvent scope causes segmentation fault, thats the problem.

                    lprzenioslo.zut.edu.pl

                    P 1 Reply Last reply 16 Apr 2015, 09:07
                    0
                    • B Bremenpl
                      16 Apr 2015, 09:05

                      @p3c0
                      Accesing undoView in resizeEvent scope causes segmentation fault, thats the problem.

                      P Offline
                      P Offline
                      p3c0
                      Moderators
                      wrote on 16 Apr 2015, 09:07 last edited by p3c0
                      #10

                      @Bremenpl Ok. So is undoView initialized before using it ?

                      157

                      B 1 Reply Last reply 16 Apr 2015, 09:11
                      0
                      • P p3c0
                        16 Apr 2015, 09:07

                        @Bremenpl Ok. So is undoView initialized before using it ?

                        B Offline
                        B Offline
                        Bremenpl
                        wrote on 16 Apr 2015, 09:11 last edited by
                        #11

                        @p3c0
                        Theres an initialisation of the pointer in the class header:

                        QUndoView *undoView;
                        

                        Then In the mainwindow constructor I am running:

                        undoStack = new QUndoStack(this);
                        undoView = new QUndoView(undoStack);
                        undoView->setWindowTitle(tr("Command List"));
                        undoView->setWindowFlags(Qt::WindowStaysOnTopHint);
                        undoView->setAttribute(Qt::WA_QuitOnClose, false);
                        undoView->show();
                        
                        moveUndoView(); // PLEASE NOTE THAT THIS WORKS IN HERE, NO SEGFAULTS
                        

                        lprzenioslo.zut.edu.pl

                        P 1 Reply Last reply 16 Apr 2015, 09:20
                        0
                        • B Bremenpl
                          16 Apr 2015, 09:11

                          @p3c0
                          Theres an initialisation of the pointer in the class header:

                          QUndoView *undoView;
                          

                          Then In the mainwindow constructor I am running:

                          undoStack = new QUndoStack(this);
                          undoView = new QUndoView(undoStack);
                          undoView->setWindowTitle(tr("Command List"));
                          undoView->setWindowFlags(Qt::WindowStaysOnTopHint);
                          undoView->setAttribute(Qt::WA_QuitOnClose, false);
                          undoView->show();
                          
                          moveUndoView(); // PLEASE NOTE THAT THIS WORKS IN HERE, NO SEGFAULTS
                          
                          P Offline
                          P Offline
                          p3c0
                          Moderators
                          wrote on 16 Apr 2015, 09:20 last edited by
                          #12

                          @Bremenpl Does it crash when you attempt to resize manually or as soon as you execute the application ? Because resize event will be fired at application startup too. Make sure undoView was initialized prior to this first resize event.

                          157

                          B 1 Reply Last reply 16 Apr 2015, 09:29
                          1
                          • P p3c0
                            16 Apr 2015, 09:20

                            @Bremenpl Does it crash when you attempt to resize manually or as soon as you execute the application ? Because resize event will be fired at application startup too. Make sure undoView was initialized prior to this first resize event.

                            B Offline
                            B Offline
                            Bremenpl
                            wrote on 16 Apr 2015, 09:29 last edited by Bremenpl
                            #13

                            @p3c0
                            You are right, that is the problem. The thing is, that I cant really create this object before i execute this->show() (MainWindow), because the program crashes as well.

                            Edit: undoStack and undoView had to be both declared before ui is build, I have forgot about that one. Now everything works, thank you a lot for help!

                            lprzenioslo.zut.edu.pl

                            P 1 Reply Last reply 16 Apr 2015, 09:45
                            0
                            • B Bremenpl
                              16 Apr 2015, 09:29

                              @p3c0
                              You are right, that is the problem. The thing is, that I cant really create this object before i execute this->show() (MainWindow), because the program crashes as well.

                              Edit: undoStack and undoView had to be both declared before ui is build, I have forgot about that one. Now everything works, thank you a lot for help!

                              P Offline
                              P Offline
                              p3c0
                              Moderators
                              wrote on 16 Apr 2015, 09:45 last edited by
                              #14

                              @Bremenpl You're Welcome :) You can mark the post as solved by editing the post title and prepending [Solved].
                              Happy Coding..

                              157

                              1 Reply Last reply
                              0

                              1/14

                              16 Apr 2015, 06:34

                              • Login

                              • Login or register to search.
                              1 out of 14
                              • First post
                                1/14
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • Users
                              • Groups
                              • Search
                              • Get Qt Extensions
                              • Unsolved