user1913171
user1913171

Reputation: 283

How to get coordinates of QToolBar icons in PyQt4 application?

I'd like to know how to set position of QCalendarWidget just below the button of ToolBar.

Currently, when user clicks a icon button inside red box, enter image description here

then the below Calendar() instance is created and the instance is shown in the middle of screen.

enter image description here

What I want to implement is like the following.

enter image description here

You can refer full source code from here.

Any suggestion or advice will be appreciated.

Upvotes: 1

Views: 276

Answers (2)

ekhumoro
ekhumoro

Reputation: 120578

This functionality is already provided by QDateTimeEdit, so you don't need a separate button for it:

    def init_toolbar(self):
        ...
        dtedit = QtGui.QDateTimeEdit()
        dtedit.setCalendarPopup(True)

Qt Docs: QDateTimeEdit.setCalendarPopup.

Upvotes: 2

Brendan Abel
Brendan Abel

Reputation: 37499

This is usually done with a combination of using QWidget.geometry() or QWidget.rect() to get the size and position of a widget (in this case, the clicked button) and then using the QWidget.mapFromXXX and QWidget.mapToXXX series of functions, to transform those into global coordinates and then into widget coordinates that can be fed to QWidget.move()

Upvotes: 1

Related Questions