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.

asked Apr 6, 2018 at 13:17

1 Answer 1

7

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.

answered Apr 6, 2018 at 13:20

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.