2

Where can I find a good documentation on how to refer (to call) to the Dialog created with QtDesigner? For example, a buttomBox (or any other) just created. I’m trying to make a plugin, but the tutorials I’ve seen just throw this information in and I just don’t get how to do with the others Widgets. How do I link them in my code? Where is this information? I need to know it for PyQt4. The API I find is not in python. Or is just specified for the use of PyQt4, and I just don’t find, or don’t understand, how to call them to my scripts I already have. PS: I use the Plugin Builder and already have some code of my own, but don’t know how to use them together to work as a plugin.

  • Are you sure to you want to keep QT4 and not QT5 ? QGIS 2 is not maintained anymore. Which QGIS version are you using? – etrimaille May 24 at 7:01
  • I am in the process of migrating from python 2 to python 3. I have some standalone scripts written with ArcPy and I'm now also migrating them to PyQGIS and trying to build some plugins for QGIS 2.18.17. If I migrate to QT5, I may have to adequate more things, and I believe, my "headache" may be bigger for now. I want to migrate to QT5 (and others) once my basics on QT4 and the understanding of the whole process of building a plugin be more concrete. Do you think I should do it otherwise? Anyone suggest a different approach? – Romário Carvalho Neto May 24 at 16:38
1

If you create a plugin with Plugin Builder Plugin, let's say a dockwidget, all in all it is self-explaning. You should see in the generated file [plugin_name]_dockwidget.py the comments

# Set up the user interface from Designer.
# After setupUI you can access any designer object by doing
# self.<objectname>, and you can use autoconnect slots - see
# http://qt-project.org/doc/qt-4.8/designer-using-a-ui-file.html
# #widgets-and-dialogs-with-auto-connect

This is from a plugin for QGIS 2, but applies also for PyQGIS 3 and explains well what to do.

For example, when you create a QPushButton named my_push_button with QtDesigner you access it via e.g.

self.my_push_button.clicked.connect(self.the_method)

within the dockwidget class, where the_method(self) is called when the button is clicked.

  • Thank you for the answer. It is a good start for me to figure it out. Any other tip for knowing what to do with the objects created? For the 'clicked.connect(self.the_method)' part, for exemplo, what else could I do? Where do I find this? This is relevant because other widgets do other things. Not all of them do simple things as only "push a button". – Romário Carvalho Neto May 24 at 16:24
  • # qt-project.org/doc/qt-4.8/designer-using-a-ui-file.html is an exemplo of what I wrote in my question: It's not python! – Romário Carvalho Neto May 24 at 17:36
  • To learn Python related topics include pyqt4 in your search strings. On riverbankcomputing.com/static/Docs/PyQt4/qabstractbutton.html for example you learn about the signals a pushbutton is able to emit (section signals). Same for other widgets. The answer above shows how to connect such a signal to a slot (function or method). – Detlev May 26 at 6:22

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.