Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. How to generate a new label each time a button is pressed?
Forum Updated to NodeBB v4.3 + New Features

How to generate a new label each time a button is pressed?

Scheduled Pinned Locked Moved Unsolved Qt for Python
2 Posts 2 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    ndkt
    wrote on last edited by ndkt
    #1

    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?

    JonBJ 1 Reply Last reply
    -1
    • N ndkt

      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?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @ndkt

      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, a QVerticalLayout. However, there are many other ways, perhaps better suited. You could, say, add them onto a QTableWidget via QTableWidgetItem(const QString &text), or use a QGridLayout which allows the adding of rows/columns, or you might pick a QListWidget 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 individual QLabels, speed & memory.

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved