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. Getting MainWindow's absolute position problem
Forum Updated to NodeBB v4.3 + New Features

Getting MainWindow's absolute position problem

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.2k 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.
  • B Offline
    B Offline
    Bremenpl
    wrote on last edited by
    #1

    Hello there,
    I have an application where I created and then show a new dialog on top of my MainWindow. Without setting the geometry, the Dialog is placed in the middle of the MainWindow. What I was trying to do, is to get the MainWindow position and add offset to it and then pass the new X and Y position to Move method. Appereantly, if I understand this correctly, I cannot read the absolute position value of the MainWindow. please, take a look at this method:

    https://pastebin.com/JF87kQ73

    In the code above I am trying to make the new Dialog appear (show) in the right-down bottom of the MainWindow. Instead, the Dialog is showing with offset starting in the upper right corner of my monitor, not the MainWindow. Is there a way to get the MainWindow absolute position? In the end, what I am trying to do, is to show the dialog on the right-down Side of the MainWindow, like this (moved this by hand):

    https://dl.dropboxusercontent.com/u/14154631/diag.png

    I Would aprichiate all help!

    lprzenioslo.zut.edu.pl

    RichardR 1 Reply Last reply
    0
    • B Bremenpl

      Hello there,
      I have an application where I created and then show a new dialog on top of my MainWindow. Without setting the geometry, the Dialog is placed in the middle of the MainWindow. What I was trying to do, is to get the MainWindow position and add offset to it and then pass the new X and Y position to Move method. Appereantly, if I understand this correctly, I cannot read the absolute position value of the MainWindow. please, take a look at this method:

      https://pastebin.com/JF87kQ73

      In the code above I am trying to make the new Dialog appear (show) in the right-down bottom of the MainWindow. Instead, the Dialog is showing with offset starting in the upper right corner of my monitor, not the MainWindow. Is there a way to get the MainWindow absolute position? In the end, what I am trying to do, is to show the dialog on the right-down Side of the MainWindow, like this (moved this by hand):

      https://dl.dropboxusercontent.com/u/14154631/diag.png

      I Would aprichiate all help!

      RichardR Offline
      RichardR Offline
      Richard
      wrote on last edited by
      #2

      @Bremenpl

      You can get the absolute position with this->pos(). So it is all in all pretty simple.
      auto p = pos();
      qDebug() << p;
      YourDialog dia(0, this);
      p += QPoint(this->width(), this->height());
      p -= QPoint(dia.width(), dia.height());
      dia.move(p);
      dia.exec();

      B 1 Reply Last reply
      0
      • RichardR Richard

        @Bremenpl

        You can get the absolute position with this->pos(). So it is all in all pretty simple.
        auto p = pos();
        qDebug() << p;
        YourDialog dia(0, this);
        p += QPoint(this->width(), this->height());
        p -= QPoint(dia.width(), dia.height());
        dia.move(p);
        dia.exec();

        B Offline
        B Offline
        Bremenpl
        wrote on last edited by Bremenpl
        #3

        @Richard
        Thank you for fast answer. For my example, the code doesnt work the way it should. I dont know either its because I am using pointer to my Dialog object, but I wouldnt say so. Please take a look at this code I have commented it:

        https://pastebin.com/5PUH2NWq

        It seems that pos() doesnt give absolute position... Could you reffer please? Heres a screen showing how the windows line up:

        https://dl.dropboxusercontent.com/u/14154631/diag2.png

        Please notice that this.pos() and undoDialog->pos() both return (0, 0) when they are created. This means that the positions are at some point relative, not absolute.

        Edit: I have read the position of undoDialog when set like this (by hand):
        https://dl.dropboxusercontent.com/u/14154631/diag.png

        its (1112, 550), while the top left corner is (0, 0).
        It seems that I can get absolute position only after I execute show() method- If I make show() (of mainwindow) to execute before your code, then it works :).

        lprzenioslo.zut.edu.pl

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Mario84
          wrote on last edited by Mario84
          #4

          Are you calling MainWindow::InitComponents() from the MainWindow's constructor?
          In this case you have to know that position and size is not yet initialized at this time...

          You could use a singleshot-Timer (with interval 0) to schedule MainWindow::InitComponents() to be run from the eventloop shortly after construction. Then the position should be initialized.
          (There's another function to add something to the eventloop that's a better solution, but I can't remember the name...)

          Edit:
          Oops, I see you found the solution yourself... Didn't read your post to the end, sorry ;-)

          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