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

QPushbutton movable Dynamically

Scheduled Pinned Locked Moved Unsolved General and Desktop
52 Posts 6 Posters 17.9k 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.
  • A Apeksha

    Hi ,

    No, it should called when user wil resize the gui using mouse.

    mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by
    #10

    @Apeksha

    Sorry i do not understand what is wrong.

    The resizeEvent will be called when user resize the running app.

    Are you talking about inside Designer part, where you do widget design or where do you mean?

    is your widget a Designer plugin ?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Apeksha
      wrote on last edited by
      #11

      Hi,

      You have said when resize event is used, it calls when user resize the running app.

      So I have done when user user resizes the app, then button have to move its Y axis, so i have written my code as follows:
      void MainWindow::resizeEvent(QResizeEvent* event)
      {
      qDebug("ResizeEvent");
      ui->pushButton->move(0,0);
      QMainWindow::resizeEvent(event);
      }

      But when my is running, without resizing app, button position is changing, my requirement is when user resizes app then only button position i.e, y-axis have to change, I hope you got my point

      jsulmJ mrjjM 2 Replies Last reply
      0
      • A Apeksha

        Hi,

        You have said when resize event is used, it calls when user resize the running app.

        So I have done when user user resizes the app, then button have to move its Y axis, so i have written my code as follows:
        void MainWindow::resizeEvent(QResizeEvent* event)
        {
        qDebug("ResizeEvent");
        ui->pushButton->move(0,0);
        QMainWindow::resizeEvent(event);
        }

        But when my is running, without resizing app, button position is changing, my requirement is when user resizes app then only button position i.e, y-axis have to change, I hope you got my point

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #12

        @Apeksha Why do you position the button manually? Why not just use layouts?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Apeksha
          wrote on last edited by
          #13

          I am having some labels,lineedits and buttons in my gui, my requirement is when user resizes gui, then button have to change position.

          1 Reply Last reply
          0
          • A Apeksha

            Hi,

            You have said when resize event is used, it calls when user resize the running app.

            So I have done when user user resizes the app, then button have to move its Y axis, so i have written my code as follows:
            void MainWindow::resizeEvent(QResizeEvent* event)
            {
            qDebug("ResizeEvent");
            ui->pushButton->move(0,0);
            QMainWindow::resizeEvent(event);
            }

            But when my is running, without resizing app, button position is changing, my requirement is when user resizes app then only button position i.e, y-axis have to change, I hope you got my point

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #14

            @Apeksha
            Ahhh, now i understand.
            Well, there is no way to tell if done by system at start up or by the user.
            But should it not do the same ?
            Or only if size is smaller then the start size or ? what is the rule?

            1 Reply Last reply
            0
            • A Offline
              A Offline
              Apeksha
              wrote on last edited by
              #15

              Hi,
              There is no way to do as per my requirement, when user resizes app, then button has to change its position.

              mrjjM 1 Reply Last reply
              0
              • A Apeksha

                Hi,
                There is no way to do as per my requirement, when user resizes app, then button has to change its position.

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #16

                Hi
                resizeEvent(event) is the way to do it.
                You just need to make sure then you do not react to the first resize events you get when app starts up.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  Apeksha
                  wrote on last edited by
                  #17

                  Hi,

                  I am using resizeevent , but my button is moving initially when app runs, but it have to move when I resize my gui.
                  void MainWindow::resizeEvent(QResizeEvent* event)
                  {
                  qDebug("ResizeEvent");
                  ui->pushButton->move(0,0);
                  QMainWindow::resizeEvent(event);
                  }
                  this is the way I am doing, any correction?

                  mrjjM 1 Reply Last reply
                  0
                  • A Apeksha

                    Hi,

                    I am using resizeevent , but my button is moving initially when app runs, but it have to move when I resize my gui.
                    void MainWindow::resizeEvent(QResizeEvent* event)
                    {
                    qDebug("ResizeEvent");
                    ui->pushButton->move(0,0);
                    QMainWindow::resizeEvent(event);
                    }
                    this is the way I am doing, any correction?

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #18

                    @Apeksha

                    That is fine. but you will also do on first resize
                    to avoid that, make some if statements
                    the event has both oldSize and newSixe to check

                    I cannot tell you what to write as i dont know
                    what the rules are to move the button.
                    At what sizes etc.

                    You can also use a timer to only allowed after say 10 secs to
                    avoid doing it on first resize.

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      Apeksha
                      wrote on last edited by
                      #19

                      Hi,

                      k, Assume my gui isof width and height 500,500, its resized to 400,400 then button has to change position, can u share sample code, I am not getting how to make

                      jsulmJ 1 Reply Last reply
                      0
                      • A Apeksha

                        Hi,

                        k, Assume my gui isof width and height 500,500, its resized to 400,400 then button has to change position, can u share sample code, I am not getting how to make

                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #20

                        @Apeksha Just add a boolean variable to your class and set it to false in the resizeEvent:

                        MainWindow::MainWindow(...): firstTime(true)
                        {
                            ...
                        }
                        void MainWindow::resizeEvent(QResizeEvent* event)
                        {
                            qDebug("ResizeEvent");
                            if (!firstTime) {
                                ui->pushButton->move(0,0);
                            } else {
                                firstTime = false;
                            }
                            QMainWindow::resizeEvent(event);
                        }
                        

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        1
                        • A Offline
                          A Offline
                          Apeksha
                          wrote on last edited by
                          #21

                          Hi jsulm,
                          Thank you so much, its very helpful.
                          Again If i maximize my gui to original size, how to make button position to original position?

                          jsulmJ 1 Reply Last reply
                          0
                          • A Apeksha

                            Hi jsulm,
                            Thank you so much, its very helpful.
                            Again If i maximize my gui to original size, how to make button position to original position?

                            jsulmJ Offline
                            jsulmJ Offline
                            jsulm
                            Lifetime Qt Champion
                            wrote on last edited by
                            #22

                            @Apeksha I don't know who you're going to position this button. What is the logic for positioning it?

                            https://forum.qt.io/topic/113070/qt-code-of-conduct

                            1 Reply Last reply
                            0
                            • A Offline
                              A Offline
                              Apeksha
                              wrote on last edited by
                              #23

                              @jsulm Same thing I was confused, Now If my gui is of 500,500(width,height), If i resized it to some 300,400 then button position will change. Now my doubt is if gui is maximized i.e to original size(500,500), how to move buttonto original position?

                              Taz742T jsulmJ 2 Replies Last reply
                              0
                              • A Apeksha

                                @jsulm Same thing I was confused, Now If my gui is of 500,500(width,height), If i resized it to some 300,400 then button position will change. Now my doubt is if gui is maximized i.e to original size(500,500), how to move buttonto original position?

                                Taz742T Offline
                                Taz742T Offline
                                Taz742
                                wrote on last edited by
                                #24

                                @Apeksha
                                save coordinates

                                Do what you want.

                                mrjjM 1 Reply Last reply
                                2
                                • Taz742T Taz742

                                  @Apeksha
                                  save coordinates

                                  mrjjM Offline
                                  mrjjM Offline
                                  mrjj
                                  Lifetime Qt Champion
                                  wrote on last edited by mrjj
                                  #25

                                  @Apeksha

                                  you can just store its old position ?

                                  QRect oldpos; // int the class

                                  void MainWindow::resizeEvent(QResizeEvent* event)
                                  {
                                      qDebug("ResizeEvent");
                                      if (!firstTime) {
                                       oldpos=ui->pushButton->geometry();
                                          ui->pushButton->move(0,0);
                                      } else {
                                          firstTime = false;
                                      }
                                      QMainWindow::resizeEvent(event);
                                  }
                                  
                                  1 Reply Last reply
                                  1
                                  • A Apeksha

                                    @jsulm Same thing I was confused, Now If my gui is of 500,500(width,height), If i resized it to some 300,400 then button position will change. Now my doubt is if gui is maximized i.e to original size(500,500), how to move buttonto original position?

                                    jsulmJ Offline
                                    jsulmJ Offline
                                    jsulm
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #26

                                    @Apeksha I still don't understand why you position this button manually...

                                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                                    1 Reply Last reply
                                    0
                                    • A Offline
                                      A Offline
                                      Apeksha
                                      wrote on last edited by
                                      #27

                                      @mrjj

                                      QRect oldpos; // int the class

                                      void MainWindow::resizeEvent(QResizeEvent* event)
                                      {
                                      qDebug("ResizeEvent");
                                      if (!firstTime) {
                                      oldpos=ui->pushButton->geometry();
                                      ui->pushButton->move(0,0);
                                      } else {
                                      firstTime = false;
                                      }
                                      QMainWindow::resizeEvent(event);
                                      }

                                      Here we are saving old geometry, again where we set this geometry?

                                      Taz742T 1 Reply Last reply
                                      0
                                      • A Apeksha

                                        @mrjj

                                        QRect oldpos; // int the class

                                        void MainWindow::resizeEvent(QResizeEvent* event)
                                        {
                                        qDebug("ResizeEvent");
                                        if (!firstTime) {
                                        oldpos=ui->pushButton->geometry();
                                        ui->pushButton->move(0,0);
                                        } else {
                                        firstTime = false;
                                        }
                                        QMainWindow::resizeEvent(event);
                                        }

                                        Here we are saving old geometry, again where we set this geometry?

                                        Taz742T Offline
                                        Taz742T Offline
                                        Taz742
                                        wrote on last edited by
                                        #28

                                        @Apeksha

                                        void MainWindow::resizeEvent(QResizeEvent* event) {
                                            qDebug("ResizeEvent");
                                            if (!firstTime) {
                                               oldpos=ui->pushButton->geometry();
                                               oldX = oldpos.X;
                                               oldY = oldpos.Y;
                                               ui->pushButton->move(0,0);
                                            } else {
                                               firstTime = false;
                                               ui->pushButton->move(oldX, oldY);
                                            }
                                           QMainWindow::resizeEvent(event);
                                        }
                                        

                                        Do what you want.

                                        1 Reply Last reply
                                        0
                                        • A Offline
                                          A Offline
                                          Apeksha
                                          wrote on last edited by
                                          #29

                                          @Taz742

                                          void MainWindow::resizeEvent(QResizeEvent* event)
                                          {
                                          oldpos=ui->pushButton->geometry();
                                          int oldx=oldpos.x();
                                          int oldy=oldpos.y();
                                          qDebug()<<"oldpos x is"<<oldx<<"oldpos y is:"<<oldy;
                                          if (!firstTime) {
                                          ui->pushButton->move(50,100);
                                          }
                                          else {
                                          firstTime = false;
                                          ui->pushButton->move(oldx,oldy);
                                          }

                                              QMainWindow::resizeEvent(event);
                                          

                                          }

                                          But it's not working, button is not moving to old position again when gui is maximized.

                                          mrjjM 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