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
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Cast event when window size is changed

Scheduled Pinned Locked Moved General and Desktop
maximize
14 Posts 2 Posters 7.3k Views 2 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.
  • B Bremenpl

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

    p3c0P Offline
    p3c0P Offline
    p3c0
    Moderators
    wrote on 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
    0
    • p3c0P p3c0

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

      p3c0P 1 Reply Last reply
      0
      • B Bremenpl

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

        p3c0P Offline
        p3c0P Offline
        p3c0
        Moderators
        wrote on last edited by
        #6

        @Bremenpl And what is UndoView ? What type ?

        157

        B 1 Reply Last reply
        0
        • p3c0P p3c0

          @Bremenpl And what is UndoView ? What type ?

          B Offline
          B Offline
          Bremenpl
          wrote on 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

          p3c0P 1 Reply Last reply
          0
          • B Bremenpl

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

            p3c0P Offline
            p3c0P Offline
            p3c0
            Moderators
            wrote on 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
            0
            • p3c0P p3c0

              @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 last edited by Bremenpl
              #9

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

              lprzenioslo.zut.edu.pl

              p3c0P 1 Reply Last reply
              0
              • B Bremenpl

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

                p3c0P Offline
                p3c0P Offline
                p3c0
                Moderators
                wrote on last edited by p3c0
                #10

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

                157

                B 1 Reply Last reply
                0
                • p3c0P p3c0

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

                  B Offline
                  B Offline
                  Bremenpl
                  wrote on 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

                  p3c0P 1 Reply Last reply
                  0
                  • B Bremenpl

                    @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
                    
                    p3c0P Offline
                    p3c0P Offline
                    p3c0
                    Moderators
                    wrote on 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
                    1
                    • p3c0P p3c0

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

                      p3c0P 1 Reply Last reply
                      0
                      • B Bremenpl

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

                        p3c0P Offline
                        p3c0P Offline
                        p3c0
                        Moderators
                        wrote on 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

                        • Login

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