[PyQt] Getting QPushButton's coordinates
Joel B. Mohler
joel at kiwistrawberry.us
Sat Jan 28 10:40:22 GMT 2012
On 01/27/2012 07:25 PM, Osman Alperen Elhan wrote:
> as i mentioned in the subject how can i get the coordinates of the
> specific button. For example:
>
> button = self.ui.buttonGroup.button(buttonId)
>
> i want to change this buttons coordinate according to its current
> coordinate. How can i do that? I am kind of new to pyqt:). Thanks
I mean this in the kindest way, but it sounds like you are "doing it
wrong" (tm). I'm assuming that self.ui.buttonGroup is a
QDialogButtonBox. If so, I suspect you should be considering the use of
the various ButtonRole types to organise your buttons by the broad
functionality they offer. Then Qt will layout your buttons according to
your platform of use to match the HIG. See
http://developer.qt.nokia.com/doc/qt-4.8/qdialogbuttonbox.html
If that really is not sufficient for your needs, then I'd suspect it
would be quite a fight with the QDialogButtonBox to do what you want
(e.g. I would assume that the QDialogButtonBox would totally rebuild the
positions every time you resize the dialog). In that case, you should
perhaps consider using a QVBoxLayout or QHBoxLayout and using the
addStretch, insertSpacing, etc functions to insert dead space in your
layouts. This can be done in the Qt Creator designer as well (there's a
spacer item in the widget toolbox).
All that failing, your question is literally answered with
button.geometry() and button.setGeometry() where the geometry property
is inherited by QPushButton from QWidget.
Joel
More information about the PyQt
mailing list