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?
-
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
QLabels, and add those onto, say, aQVerticalLayout. However, there are many other ways, perhaps better suited. You could, say, add them onto aQTableWidgetviaQTableWidgetItem(const QString &text), or use aQGridLayoutwhich allows the adding of rows/columns, or you might pick aQListWidgetto 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 individualQLabels, speed & memory.