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. Window position with respect to screen and width and height of window
Qt 6.11 is out! See what's new in the release blog

Window position with respect to screen and width and height of window

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 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.
  • A Offline
    A Offline
    Andrew
    wrote on last edited by
    #1

    Hi

    Using Qt 4.8
    I am trying to bind mouse cursor to the center of my application.

    If application is in fullscreen it works with following code
    @
    int middleX = QApplication::desktop()->width() >> 1;
    int middleY = QApplication::desktop()->height() >> 1;

    QPoint newMousePos;
    newMousePos.setX(middleX);
    newMousePos.setY(middleY);
    QCursor::setPos(newMousePos);
    

    @

    and it works.

    But how do I do this when application is not fullscreen mode?

    Thanks in advance

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      Every QWidget has methods to map between the relevant coordinate systems. Did you look into these?

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Andrew
        wrote on last edited by
        #3

        Thanks for the reply Andre.

        I tried various codes on the web, having frameGeometry() and many things
        But nothing seems to work

        I would appreciate if you can demonstrate some code

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          Do it in steps:

          get the center point of the geometry of your window.

          then, map that coordinate to the right coordinate system (look for functions in QWidget that start with mapTo and mapFrom)

          set the mouse using those coordinates.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Andrew
            wrote on last edited by
            #5

            Well, I think I understand these steps. I have already done this for fullscreen mode.

            I do not know "exactly how" to get the geometry of the window? Once I have that things will be easy..

            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