3

I am writing a new plugin for QGIS 2.18. I can't find what are the libraries to import in my main code to access widgets such as QgsSpinBox or QgsFileWidget.

1 Answer 1

6

To properly use QT QGis custom widgets: Use imports such as: from PyQt4.QtGui import QDialog from qgis.gui import QgsFileWidget

You must also edit the xx_dialog_base.ui file, to ensure that the widgets are imported from the python module and not from the C libraries (it seems there is a bug in the generation of this .ui file, see Plugins crashing with "No module named qgsprojectionselectionwidget" in Windows?)

For example:

 <customwidget>
   <class>QgsProjectionSelectionWidget</class>
   <extends>QWidget</extends>
   <header>qgsprojectionselectionwidget.h</header>
  </customwidget>

must be edited as:

<customwidget>
   <class>QgsProjectionSelectionWidget</class>
   <extends>QWidget</extends>
   <header>qgis.gui</header>
  </customwidget>

It seems this edit as to be repeated every time the .ui file is saved by QT designer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.