Get real top left corner of QToolButton
-
Hi,
I have a QToolButton placed on a screen with features multiple frames and other layout widgets and I would like to extend other widgets on click of the button but for positioning of that custom widget, I need to find the top left corner of the QToolButton, I've tried
btn.x()
andbtn.y()
but the coordinates returned do clearly not align with the actual position of the button. I wrote a little test program which does not feature any layouts andbtn.x()
andbtn.y()
seem to be returning the correct values. How do I get the real position if the QToolButton is positioned inside layouts? -
if you by "absolute display position" mean the x,y on the screen.
I see, I wasn't particular enough, I actually mean the position in the Window. I will look at the link, Thank you!
If your
QToolButton
is located in your widget (the one you want to map to), you can usemapToParent
ormapTo(widget)
.
If it's not a direct parent, you couldmapToGlobal
first and thenmapFromGlobal
to get the point in your widget's coordinates. -
Hi,
QWidget::x value is relative to its parent, did you take that into account ?
-
Hi,
QWidget::x value is relative to its parent, did you take that into account ?
@SGaist said in Get real top left corner of QToolButton:
Hi,
QWidget::x value is relative to its parent, did you take that into account ?
OIps, you're right: "This property holds the x coordinate of the widget relative to its parent including any window frame"
I want to get the absolute display position and should be looking at QRect then I guess... Thanks! -
@SGaist said in Get real top left corner of QToolButton:
Hi,
QWidget::x value is relative to its parent, did you take that into account ?
OIps, you're right: "This property holds the x coordinate of the widget relative to its parent including any window frame"
I want to get the absolute display position and should be looking at QRect then I guess... Thanks!@cerr
Hi
You should have a look at
https://doc.qt.io/qt-5/qwidget.html#mapToGlobalif you by "absolute display position" mean the x,y on the screen.
-
@cerr
Hi
You should have a look at
https://doc.qt.io/qt-5/qwidget.html#mapToGlobalif you by "absolute display position" mean the x,y on the screen.
-
if you by "absolute display position" mean the x,y on the screen.
I see, I wasn't particular enough, I actually mean the position in the Window. I will look at the link, Thank you!
If your
QToolButton
is located in your widget (the one you want to map to), you can usemapToParent
ormapTo(widget)
.
If it's not a direct parent, you couldmapToGlobal
first and thenmapFromGlobal
to get the point in your widget's coordinates.