Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Example for configuration dialog with qlistwidget and qstackedwidget ?
I'm looking for an example of how to develop a configuration dialog with qlistwidget and qstackedwidget.
Thanks for your reply.
I was looking for an example like this:
QListWidget and QStackedWidget
I found an older example here:
Okay the thing on the left would most likely be a QListWidget and the stuff on the right as @jsulm pointed out is a QTabWidget which is very similar to a QStackWidget you just get that fancy Tab representation at the top. I would think that these 2 objects are then contained within a QSplitter. Then that stuff on the bottom and the top would be contained within a QHBoxLayout then finally all of that gets stuck into a QVBoxLayout
I think, its like this:
No the QStackedWidget (over the QTabWidget) is unnecessary if you are using QTabWidget they are redundant in many ways
I am not sure about your Kits -- as initially that is a QTreeView or QTreeWidget depending on your needs -- next QDialog I think could be replaced with a simple QWidget not sure you using properly here then again I am not sure what that Kits Tab is supposed to be representing -- and/or perhaps it is being implemented unnecessarily complicated not sure without fully understanding what its purpose is and what it is supposed to be doing
Oh and missed seeing it -- the thing on the bottom is not a QDialog Widget just a QWidget is all you need if you want to put them all within a Widget -- otherwise QHBoxLayout is sufficient
Also I do not think you understand what QHBoxLayout and QVBoxLayout are used for within PyQt
NonNT last edited by NonNT
Screenshot is the options dialog of Qt Creator.
Then its like this:
QVBoxLayout QHBoxLayout QVBoxLayout QLineEdit QListWidget | QTreeWidget QVBoxLayout QLabel QTabWidget | QStackedWidget QDialogButtonBox
You had it correctly, the first time. The QStackedWidget will be used to switch between the various widgets that are related to the selection you have in the QListWidget.
In the example you have, the QTabWidget is part of the widget that that is related to the Kits. That "KitsWidget" is contained in the QStackedWidget.
The example is the options dialog of Qt Creator.
@SGaist I have never had to use a QStackWidget in conjunction with a QTabWidget -- as the QTabWidget is a container just like QStackWidget --- so I am not seeing why it would even be needed if the QTabWidget is created and used properly. Further this is how I might do it
QHBoxLayout QVBoxLayout QLineEdit QListWidget QVBoxLayout QLabel QTabWidget QWidget(1) Widgets Contained within Tab1 QWidget(2) Widgets Contained within Tab2 QWidget(3) Widgets Contained within Tab3 QWidget(4) Widgets Contained within Tab4 QWidget(5) Widgets Contained within Tab5 QWidget(6) Widgets Contained within Tab6 QHBoxLayout addStretch(1) addWidget(self.btnOkay) addWidget(self.btnApply) addWidget(self.btnCancel) # If anyone wants more extensive free help I run an online lab-like classroom-like # message server feel free and drop by you will not be able to post until I clear # you as a student as this prevents spammers so if interested here is the invite # https://discord.gg/3D8huKC
@Denni-0 one example would be a configuration dialog which can be dynamically extended using plugins. Each plugin can provide its own configuration widget. In this case why should the dialog start fiddling with a QTabWidget ? Each configuration widget is that: one widget. The fact that it uses QTabWidget internally because it has several different aspects to configure or simply one QLineEdit is an implementation detail. Hence the combination of a QListView/Widget and a QStackedWidget which current index depends on the selected item in said QListView/Widget.
Denni 0 Banned last edited by
Okay @SGaist that was rather confuzzling -- and seems overtly complex and/or are you saying you can do this without even using QTabWidget -- if the latter okay but that was not the question? Can you please clarify your statement I would like to understand what you are saying
The idea behind a preference widget like shown here is that for each entry in the QListWidget, you have an independent widget shown. Hence the use of QStackedWidget. The fact that there might be a QTabWidget in one or more of these widgets is a technical detail. This allows you to design freely these widget without having to modify the dialog to fiddle with adding and removing tabs each time you click a different item in the list widget.
Okay that is not what I was understanding the OP was doing -- and the fact that QTabWidget can and does hold onto these various Widgets in a similar manner to QStackedWidget does IMHO make the usage of that latter redundant when used in conjunction with the former.
Basically it would be like creating a List putting into a Dictionary and putting that Dictionary into another Dictionary but gaining nothing from doing so other than another layer of referencing such as
Key1 = 1 QDict1[Key1] = QList Key2 = 10 QDict2[Key2] = QDict1
And the only reason the value of Key was changed from dictionary to dictionary was to reflect the reference value of one to the next having been changed but still just being a meaningless value to the programmer other than a handle to the QList which in QDict2 is a handle to a Dict to a handle to a QList instead of just a handle to a QList (aka making it more complex that is necessary)