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 19.1k 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

    @mrjj

    I understood saving of old position and new position, but how to restore i.e hoe to set button old position to restore?

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

    @Apeksha Like this maybe?

    ui->pushButton->move(oldX, oldY);
    

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

    A 1 Reply Last reply
    0
    • jsulmJ jsulm

      @Apeksha Like this maybe?

      ui->pushButton->move(oldX, oldY);
      
      A Offline
      A Offline
      Apeksha
      wrote on last edited by Apeksha
      #43

      @jsulm

      I have used the same, but it's not working.

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

          else {
               ui->pushButton->move(oldx,oldy);
                 firstTime = false;
      
          }
      
          QMainWindow::resizeEvent(event);
      

      }

      jsulmJ 1 Reply Last reply
      0
      • A Apeksha

        @jsulm

        I have used the same, but it's not working.

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

            else {
                 ui->pushButton->move(oldx,oldy);
                   firstTime = false;
        
            }
        
            QMainWindow::resizeEvent(event);
        

        }

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

        @Apeksha "it's not working" doesn't help to solve the problem.
        Did you analyse why it is not working? You can print out the values oldX, oldY for example.

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

        A 1 Reply Last reply
        0
        • jsulmJ jsulm

          @Apeksha "it's not working" doesn't help to solve the problem.
          Did you analyse why it is not working? You can print out the values oldX, oldY for example.

          A Offline
          A Offline
          Apeksha
          wrote on last edited by
          #45

          @jsulm

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

          else {
               ui->pushButton->move(oldx,oldy);
                 firstTime = false;
          
          }
          
          QMainWindow::resizeEvent(event);
          

          }

          A 1 Reply Last reply
          0
          • A Apeksha

            @jsulm

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

            else {
                 ui->pushButton->move(oldx,oldy);
                   firstTime = false;
            
            }
            
            QMainWindow::resizeEvent(event);
            

            }

            A Offline
            A Offline
            Apeksha
            wrote on last edited by Apeksha
            #46

            Hi,

            please can anybody help me to solve this issue?

            Thanks in advance.

            jsulmJ 1 Reply Last reply
            0
            • A Apeksha

              Hi,

              please can anybody help me to solve this issue?

              Thanks in advance.

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

              @Apeksha Your current resizeEvent is wrong: you read CURRENT button geometry and use it as OLD geometry! You need to store the old posx/posy before and restore it later when needed.

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

              A 1 Reply Last reply
              0
              • jsulmJ jsulm

                @Apeksha Your current resizeEvent is wrong: you read CURRENT button geometry and use it as OLD geometry! You need to store the old posx/posy before and restore it later when needed.

                A Offline
                A Offline
                Apeksha
                wrote on last edited by
                #48

                @jsulm

                K i uderstood , Initially I will save oldx and oldy in constructor and where actually i have to use this oldx and oldy to restore. In above code If I use this oldx and oldy , its not restoring. I am attaching code:

                void MainWindow::resizeEvent(QResizeEvent* event)
                {
                if (!firstTime) {
                ui->pushButton->move(50,100);
                }

                    else {             
                        ui->pushButton->move(oldx,oldy);  ---->This oldx and oldy Iam  storing in constructor.
                           firstTime = false;
                    }
                
                    QMainWindow::resizeEvent(event);
                

                }

                jsulmJ 1 Reply Last reply
                0
                • A Apeksha

                  @jsulm

                  K i uderstood , Initially I will save oldx and oldy in constructor and where actually i have to use this oldx and oldy to restore. In above code If I use this oldx and oldy , its not restoring. I am attaching code:

                  void MainWindow::resizeEvent(QResizeEvent* event)
                  {
                  if (!firstTime) {
                  ui->pushButton->move(50,100);
                  }

                      else {             
                          ui->pushButton->move(oldx,oldy);  ---->This oldx and oldy Iam  storing in constructor.
                             firstTime = false;
                      }
                  
                      QMainWindow::resizeEvent(event);
                  

                  }

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

                  @Apeksha Did you verify the else block was executed? Did you check the oldx/oldy values?

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

                  A 1 Reply Last reply
                  0
                  • jsulmJ jsulm

                    @Apeksha Did you verify the else block was executed? Did you check the oldx/oldy values?

                    A Offline
                    A Offline
                    Apeksha
                    wrote on last edited by
                    #50

                    @jsulm

                    Very first time it was executing, when I am resizing it was not executing.

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      dsba
                      wrote on last edited by
                      #51

                      @Apeksha

                      I think, Problem seems to be with enabling of flag "firsttime".

                      CAN YOU TRY THIS?

                      int oldX,oldY,fstFlag=1;

                      void MainWindow::resizeEvent(QResizeEvent *event)
                      {
                      if(!fstFlag)
                      {
                      oldX=0;
                      oldY=0;
                      fstFlag=1;
                      }
                      else
                      {
                      fstFlag=0;
                      oldX=50;
                      oldY=100;
                      }
                      ui->pushbutton->move(oldX,oldY);
                      }

                      A 1 Reply Last reply
                      0
                      • D dsba

                        @Apeksha

                        I think, Problem seems to be with enabling of flag "firsttime".

                        CAN YOU TRY THIS?

                        int oldX,oldY,fstFlag=1;

                        void MainWindow::resizeEvent(QResizeEvent *event)
                        {
                        if(!fstFlag)
                        {
                        oldX=0;
                        oldY=0;
                        fstFlag=1;
                        }
                        else
                        {
                        fstFlag=0;
                        oldX=50;
                        oldY=100;
                        }
                        ui->pushbutton->move(oldX,oldY);
                        }

                        A Offline
                        A Offline
                        Apeksha
                        wrote on last edited by Apeksha
                        #52

                        @dsba

                        Thanks a lot.
                        Its fine, but when I am resizing my app slowly button is blinking.

                        1 Reply Last reply
                        1

                        • Login

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