Python – Positioning the Qwidget Form/QDialogBox in the Left Corner

pyqgispyqtpythonqgisqt

1) I am creating a Qwidget Form or QDialogBox using QT Designer. I am using the following code to move the form:

sDialog.move(50,450)

But i want to fit the dialogBox to fit in the left corner.How can i do that using Python programming?

2) When i am using the Canvas events if i click on the map dialogBox/Form is hiding but i want to fit the position so if we do any thing on the map also the DialogBox should nt hide.How can i do that using python programming?

Best Answer

I'll answer the question that is stated in the title.

You can use the following code to show your dialog in the bottom-left corner (do all this right before the call to self.dlg.show()):

    ph = self.dlg.parent().geometry().height()
    px = self.dlg.parent().geometry().x()
    py = self.dlg.parent().geometry().y()
    dw = self.dlg.width()
    dh = self.dlg.height()   
    self.dlg.setGeometry( px, py+ph-dh, dw, dh )

If you want your dialog at the top-left corner, change the second parameter of setGeometry() to py.

As for your second question, I cannot replicate that. Have a look at my plugin Synchronize QGIS with a directory, the dialog is not hidden when I interact with the map via map tools.


By the way, you should really ask a single question per post. Otherwise you discourage people to answer your questions.