How to generate a new label each time a button is pressed?
-
I would like to show the updated result of my dictionary. Currently, I think the way to show value of the dictionary is by set text on a label... is there a way I can generate a new label each time a button is pressed. Or is there another way that doesn't use text label that I should use?
-
is there a way I can generate a new label each time a button is pressed.
Yes. In your slot (just like anywhere else) you can create widgets dynamically by
newLabel = QLabel()
or similar, and then add the new widget wherever appropriate somewhere in your widget hierarchy.Or is there another way that doesn't use text label that I should use?
You could represent these via individual
QLabel
s, and add those onto, say, aQVerticalLayout
. However, there are many other ways, perhaps better suited. You could, say, add them onto aQTableWidget
viaQTableWidgetItem(const QString &text)
, or use aQGridLayout
which allows the adding of rows/columns, or you might pick aQListWidget
to store/show them as a list in a single widget, which would be my first inclination. Especially if there are going to be a large number of items, you don't want to create a large number of individualQLabel
s, speed & memory.