Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Using PyQt5 Objects inside QTabWidget and QScrollArea - QGIS Plugin



  • I'm using PyQt5 and QT Designer to create the user interface for my QGIS plugin. Now I'm learning to use QTabWidget and QScrollArea. What I don't understand is how to use the objects inside tabs or scroll areas. For example in my dialog there are two tabs, inside these there's a scroll area and finally the other objects like labels, lineEdits and buttons. You can see this in the image below. The problem is that if I try to use, as usual in my run method, simple functions like: self.dlg.label_2.setText() or self.dlg.lineEdit.text(), I receive this kind of error log: AttributeError: 'Dialog' object has no attribute 'label_2'. How to solve it?

    alt text


  • Lifetime Qt Champion

    Hi,

    Might be a silly question but are you sure the widget is properly initialised ?

    On an unrelated note, you should add layouts in your widget to make placement/size management automatic.



  • Hi, many thanks for your answer. To be honest, talking about layouts, I have not studied these aspects yet. About the first question, I'm not quite sure. I know that if I don't use tabWidget or scrollArea, I can work with labels, buttons and lineEdits without problems. I don't know if there's a particulare way to initialise tabWidget and scollArea, note that I'm using QtDesigner.


  • Lifetime Qt Champion

    Without seeing the code you are using I can't really comment about what is happening between the two versions of your widget.

    Depending on your fluency with developing widgets, you might also want to consider writing them by hand (it's more a question of taste).


  • Banned

    @bemlun you should do yourself a major favor and stop using the Qt Designer -- it might seem easier on the surface but under the hood it is a horrible mess and just a major headache to work with -- further you are probably not using it for what it was actually designed for.

    That being said creating using python-qt as it was meant to be used -- is rather easy once you get used to it -- further what you end up with not only do you understand how it works but you can now easily work with all the elements of the Gui because you fully understand how they inter-relate -- if you need help on this just ask or shoot me a PM and I can get you hooked up with a free classroom like environment


Log in to reply