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.2k 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 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
                • A Apeksha

                  @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 Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #30

                  @Apeksha said in QPushbutton movable Dynamically:

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

                  But that is impossible for it to know.
                  You must check for that situations then. and then call the
                  ui->pushButton->move(oldx,oldy);

                  you can use isMaximized()

                  I wish i understood why you cant just use a layout :)

                  A 1 Reply Last reply
                  0
                  • mrjjM mrjj

                    @Apeksha said in QPushbutton movable Dynamically:

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

                    But that is impossible for it to know.
                    You must check for that situations then. and then call the
                    ui->pushButton->move(oldx,oldy);

                    you can use isMaximized()

                    I wish i understood why you cant just use a layout :)

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

                    @mrjj

                    My code is wrong?

                    what conditions I have to use? Can you please guide me?

                    mrjjM 1 Reply Last reply
                    0
                    • A Apeksha

                      @mrjj

                      My code is wrong?

                      what conditions I have to use? Can you please guide me?

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

                      @Apeksha

                      Not wrong as such, but you seem to except it can guess your thoughts :)

                      The resizeEvent is called when ever windows size has changes.

                      If you want to do anything , you must make the logic your self.

                      if you want to restore the button when maximized you can test with
                      isMaximized() to see if that is now. and if yes, then
                      move it back to old spot wtih ui->pushButton->move(oldx,oldy);

                      The firstTime flag only fixed the situation that you didnt not want to move it on first resize (first time shown)

                      If you want to move it back then when maximized you need some code for that too :)

                      A 1 Reply Last reply
                      0
                      • mrjjM mrjj

                        @Apeksha

                        Not wrong as such, but you seem to except it can guess your thoughts :)

                        The resizeEvent is called when ever windows size has changes.

                        If you want to do anything , you must make the logic your self.

                        if you want to restore the button when maximized you can test with
                        isMaximized() to see if that is now. and if yes, then
                        move it back to old spot wtih ui->pushButton->move(oldx,oldy);

                        The firstTime flag only fixed the situation that you didnt not want to move it on first resize (first time shown)

                        If you want to move it back then when maximized you need some code for that too :)

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

                        @mrjj

                        I have tried with ismaximized(), its not working.

                        mrjjM 1 Reply Last reply
                        0
                        • A Apeksha

                          @mrjj

                          I have tried with ismaximized(), its not working.

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

                          @Apeksha
                          it always say false ? or in what way "not working"

                          A 1 Reply Last reply
                          0
                          • ? Offline
                            ? Offline
                            A Former User
                            wrote on last edited by
                            #35

                            @jsulm said in QPushbutton movable Dynamically:

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

                            I second that. I'm so curious, pretty please with sugar on top, explain your use case.

                            A 1 Reply Last reply
                            1
                            • ? A Former User

                              @jsulm said in QPushbutton movable Dynamically:

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

                              I second that. I'm so curious, pretty please with sugar on top, explain your use case.

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

                              @Wieland

                              ui->contentWidget->setStyleSheet("QWidget {background-color:#C0C0C0;}");
                              ui->contentWidget->setMinimumSize( 820, 150 );
                              QHBoxLayout *ConfigurationLayout = new QHBoxLayout;
                              QScrollArea *scrollArea = new QScrollArea;
                              // scrollArea->setStyleSheet("QScrollArea {background-color:#C0C0C0;}");
                              scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
                              scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
                              scrollArea->setWidget(ui->contentWidget);
                              scrollArea->setWidgetResizable(true);
                              ConfigurationLayout->addWidget(scrollArea);
                              mainBoxLayout->addLayout(ConfigurationLayout);

                              This is my part of code where button movable is required, I had widget and scrollArea and some buttons.
                              So when my app is minimized, one of the button position should change, when gui is minized it have to display on top of widget. I hope you got my requirement.

                              1 Reply Last reply
                              0
                              • mrjjM mrjj

                                @Apeksha
                                it always say false ? or in what way "not working"

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

                                @mrjj

                                Yes, it always say false?

                                mrjjM 1 Reply Last reply
                                0
                                • A Apeksha

                                  @mrjj

                                  Yes, it always say false?

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

                                  @Apeksha

                                  ok didnt check it lately , i assume its because the NewSize from event has not yep been applied.

                                  I think i get your use case now
                                  the button show sort of go to next col if there is no room to be below.
                                  So its not on top of the other but on top in new col?
                                  like this
                                  alt text

                                  A 1 Reply Last reply
                                  0
                                  • mrjjM mrjj

                                    @Apeksha

                                    ok didnt check it lately , i assume its because the NewSize from event has not yep been applied.

                                    I think i get your use case now
                                    the button show sort of go to next col if there is no room to be below.
                                    So its not on top of the other but on top in new col?
                                    like this
                                    alt text

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

                                    @mrjj

                                    So what to do now? what is the solution?

                                    mrjjM 1 Reply Last reply
                                    0
                                    • A Apeksha

                                      @mrjj

                                      So what to do now? what is the solution?

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

                                      @Apeksha
                                      you can use
                                      const QSize &QResizeEvent::oldSize() const
                                      const QSize &QResizeEvent::size() const
                                      to check what size window has and had.

                                      Based on those numbers , you can do the right thing, store button pos
                                      or to restore the button to old pos.

                                      you can use qDebug() << "size" << event.oldSize() << " to " << event.Size();

                                      to get an idea of what numbers you will see.

                                      You can use
                                      http://doc.qt.io/qt-5/qdesktopwidget.html#availableGeometry

                                      to get how big screen is.

                                      A 1 Reply Last reply
                                      0
                                      • mrjjM mrjj

                                        @Apeksha
                                        you can use
                                        const QSize &QResizeEvent::oldSize() const
                                        const QSize &QResizeEvent::size() const
                                        to check what size window has and had.

                                        Based on those numbers , you can do the right thing, store button pos
                                        or to restore the button to old pos.

                                        you can use qDebug() << "size" << event.oldSize() << " to " << event.Size();

                                        to get an idea of what numbers you will see.

                                        You can use
                                        http://doc.qt.io/qt-5/qdesktopwidget.html#availableGeometry

                                        to get how big screen is.

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

                                        @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 1 Reply Last reply
                                        0
                                        • 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

                                          • Login

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