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?
-
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.
-
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).