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. Coordinates widget
Qt 6.11 is out! See what's new in the release blog

Coordinates widget

Scheduled Pinned Locked Moved Unsolved General and Desktop
17 Posts 3 Posters 2.0k Views 1 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #6

    I have a dockWidget with its original position and then I move it...after that I moved it I want that I press a button and it gets its original position in MainWindow..but I can't, Can you help me?

    jsulmJ 1 Reply Last reply
    0
    • ? A Former User

      I have a dockWidget with its original position and then I move it...after that I moved it I want that I press a button and it gets its original position in MainWindow..but I can't, Can you help me?

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

      @vale88 Did you store its original position somewhere?

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

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

        @jsulm said in Coordinates widget:

        Did you store its original position somewhere

        yes but if write move(100, 40) I don't obtain its position relative to MainWindow

        jsulmJ 1 Reply Last reply
        0
        • ? A Former User

          @jsulm said in Coordinates widget:

          Did you store its original position somewhere

          yes but if write move(100, 40) I don't obtain its position relative to MainWindow

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

          @vale88 I guess because it is inside a widget (central widget) not main window. How do you store original coordinates (can you show the code)?

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

          ? 1 Reply Last reply
          1
          • jsulmJ jsulm

            @vale88 I guess because it is inside a widget (central widget) not main window. How do you store original coordinates (can you show the code)?

            ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #10

            @jsulm #include "mainwindow.h"
            #include "ui_mainwindow.h"
            #include <QDebug>

            MainWindow::MainWindow(QWidget *parent) :
            QMainWindow(parent),
            ui(new Ui::MainWindow)
            {
            ui->setupUi(this);
            real_pos= ui->dockWidget_2->mapToGlobal(QPoint(100,40));

            }

            MainWindow::~MainWindow()
            {
            delete ui;
            }

            void MainWindow::on_pushButton_clicked()
            {
            ui->dockWidget_2->setFloating(true);
            }

            void MainWindow::on_pushButton_2_clicked()
            {
            ui->dockWidget_2->move(real_pos.x(), real_pos.y());

            }

            CP71C 1 Reply Last reply
            0
            • ? A Former User

              @jsulm #include "mainwindow.h"
              #include "ui_mainwindow.h"
              #include <QDebug>

              MainWindow::MainWindow(QWidget *parent) :
              QMainWindow(parent),
              ui(new Ui::MainWindow)
              {
              ui->setupUi(this);
              real_pos= ui->dockWidget_2->mapToGlobal(QPoint(100,40));

              }

              MainWindow::~MainWindow()
              {
              delete ui;
              }

              void MainWindow::on_pushButton_clicked()
              {
              ui->dockWidget_2->setFloating(true);
              }

              void MainWindow::on_pushButton_2_clicked()
              {
              ui->dockWidget_2->move(real_pos.x(), real_pos.y());

              }

              CP71C Offline
              CP71C Offline
              CP71
              wrote on last edited by
              #11

              @vale88 If I don't mistake, you must not use mapToGlobal because it converts widget coordinates to screen coordinates. If you want to move widget relative to MainWindows you must move to 100,40.

              So real_pos = QPoint(100, 40);

              ? 1 Reply Last reply
              1
              • CP71C CP71

                @vale88 If I don't mistake, you must not use mapToGlobal because it converts widget coordinates to screen coordinates. If you want to move widget relative to MainWindows you must move to 100,40.

                So real_pos = QPoint(100, 40);

                ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #12

                @CP71 I tried but the problem remains...I have a problem with dockwidget..they stick to mainwindow..so I must do a function with move

                CP71C 1 Reply Last reply
                0
                • ? A Former User

                  @CP71 I tried but the problem remains...I have a problem with dockwidget..they stick to mainwindow..so I must do a function with move

                  CP71C Offline
                  CP71C Offline
                  CP71
                  wrote on last edited by
                  #13

                  @vale88 Do you have a layout?

                  ? 1 Reply Last reply
                  1
                  • CP71C CP71

                    @vale88 Do you have a layout?

                    ? Offline
                    ? Offline
                    A Former User
                    wrote on last edited by
                    #14

                    @CP71 I put dockwidget in a layout of a stacked widget

                    CP71C 1 Reply Last reply
                    0
                    • ? A Former User

                      @CP71 I put dockwidget in a layout of a stacked widget

                      CP71C Offline
                      CP71C Offline
                      CP71
                      wrote on last edited by
                      #15

                      @vale88 I suppose that layout is the problem, layout is placing your widget.
                      This explains because you can't position your widget as you wish.

                      ? 1 Reply Last reply
                      2
                      • CP71C CP71

                        @vale88 I suppose that layout is the problem, layout is placing your widget.
                        This explains because you can't position your widget as you wish.

                        ? Offline
                        ? Offline
                        A Former User
                        wrote on last edited by
                        #16

                        @CP71 I want posizionate my dockwidget wherever I want, but I can't because the dockwidget attached to the MainWindow

                        CP71C 1 Reply Last reply
                        0
                        • ? A Former User

                          @CP71 I want posizionate my dockwidget wherever I want, but I can't because the dockwidget attached to the MainWindow

                          CP71C Offline
                          CP71C Offline
                          CP71
                          wrote on last edited by
                          #17

                          @vale88 Only thing that comes to mind is to move your widget out of the layout. If it is possible for your UI.

                          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