Jump to content
Sign in to follow this  

Getting absolute screen position in Python panels

Recommended Posts


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")
    if curParent == mainWindow:
        print("Stopping as main win reached")
    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.




Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this