Jump to content

Getting absolute screen position in Python panels


quryo

Recommended Posts

Hello,

I'm building a tool where I need the global screen position from a local widget position (as I'm using a QCompleter).

The usual way to do this seems to be with `QWidget::mapToGlobal`. However, the result seems to be always wrong. I believe this is because there is no full Qt widget hierarchy in the panel.

For instance, when printing the `geometry()` QRect of the widget hierarchy of a panel that is on the right side of the screen, I never see the offset on the screen that the panel obviously has:

mainWindow = hou.qt.mainWindow()
curParent = self.parent()

for i in range(0,30):
    if curParent is None:
        print("Stopping due to unparented")
        break
    if curParent == mainWindow:
        print("Stopping as main win reached")
        break
    
    print("cur ", i, ": ", str(curParent.geometry()), " mapped ", str(curParent.mapToGlobal(QtCore.QPoint(0,0))))
    curParent = curParent.parent()

results in

('cur ', 0, ': ', 'PySide.QtCore.QRect(9, 32, 589, 430)', ' mapped ', 'PySide.QtCore.QPoint(9, 32)')
('cur ', 1, ': ', 'PySide.QtCore.QRect(0, 0, 607, 471)', ' mapped ', 'PySide.QtCore.QPoint(0, 0)')
('cur ', 2, ': ', 'PySide.QtCore.QRect(0, 0, 607, 471)', ' mapped ', 'PySide.QtCore.QPoint(0, 0)')
Stopping due to unparented

 

This is in Houdini 16.5.439.

 

I'd appreciate any pointers on how to get the Houdini-internal view hierarchy or to get parenting work properly.

 

Cheers

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...