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. Pyqt5 help!!
QtWS25 Last Chance

Pyqt5 help!!

Scheduled Pinned Locked Moved Solved Qt for Python
pyqt5labels
6 Posts 5 Posters 1.1k Views
  • 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.
  • D Offline
    D Offline
    Dexter99
    wrote on last edited by
    #1

    Hi I have a program that should add about 40 labels(one at a time) when a button is clicked. Now I don't want to be an idiot and make blank labels and then change the text if those. Is there a more efficient way of displaying the labels. Thank you.

    jsulmJ 1 Reply Last reply
    0
    • D Dexter99

      Hi I have a program that should add about 40 labels(one at a time) when a button is clicked. Now I don't want to be an idiot and make blank labels and then change the text if those. Is there a more efficient way of displaying the labels. Thank you.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Dexter99 You can create widgets (like labels) dynamically and show them:

      void MainWindow::on_button_clicked()
      {
          QLabel *label = new QLabel(this, "Some text");
          // Put your label into layout or position it manually
          label->show();
      }
      

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      JonBJ 1 Reply Last reply
      1
      • jsulmJ jsulm

        @Dexter99 You can create widgets (like labels) dynamically and show them:

        void MainWindow::on_button_clicked()
        {
            QLabel *label = new QLabel(this, "Some text");
            // Put your label into layout or position it manually
            label->show();
        }
        
        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @jsulm
        Not that it matters, but for the record do you have to show() it after adding? I could swear I add dynamic labels all the time without calling show()...

        D SGaistS 2 Replies Last reply
        0
        • JonBJ JonB

          @jsulm
          Not that it matters, but for the record do you have to show() it after adding? I could swear I add dynamic labels all the time without calling show()...

          D Offline
          D Offline
          Dexter99
          wrote on last edited by
          #4

          Oooo sorry that was idiotic.

          1 Reply Last reply
          0
          • JonBJ JonB

            @jsulm
            Not that it matters, but for the record do you have to show() it after adding? I could swear I add dynamic labels all the time without calling show()...

            SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @JonB said in Pyqt5 help!!:

            @jsulm
            Not that it matters, but for the record do you have to show() it after adding? I could swear I add dynamic labels all the time without calling show()...

            If not added to a layout applied on a visible widget, then yes you have to call show.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            JonBJ 1 Reply Last reply
            1
            • SGaistS SGaist

              @JonB said in Pyqt5 help!!:

              @jsulm
              Not that it matters, but for the record do you have to show() it after adding? I could swear I add dynamic labels all the time without calling show()...

              If not added to a layout applied on a visible widget, then yes you have to call show.

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

              @SGaist
              Ah, yes, I do mean adding to already visible widget parent/layout, so that's why I don't need to.

              So, I'm not criticising @jsulm's code, but where he has added new QLabel(this, "Some text"); the this is the QMainWindow, which will be shown, so he didn't need to put in the label->show();, right?

              1 Reply Last reply
              0

              • Login

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