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!!
Forum Updated to NodeBB v4.3 + New Features

Pyqt5 help!!

Scheduled Pinned Locked Moved Solved Qt for Python
pyqt5labels
6 Posts 5 Posters 1.1k 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.
  • D Offline
    D Offline
    Dexter99
    wrote on 31 Jan 2020, 12:22 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.

    J 1 Reply Last reply 31 Jan 2020, 12:35
    0
    • D Dexter99
      31 Jan 2020, 12:22

      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.

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 31 Jan 2020, 12:35 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

      J 1 Reply Last reply 31 Jan 2020, 13:10
      1
      • J jsulm
        31 Jan 2020, 12:35

        @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();
        }
        
        J Offline
        J Offline
        JonB
        wrote on 31 Jan 2020, 13:10 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 S 2 Replies Last reply 1 Feb 2020, 15:51
        0
        • J JonB
          31 Jan 2020, 13:10

          @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 1 Feb 2020, 15:51 last edited by
          #4

          Oooo sorry that was idiotic.

          1 Reply Last reply
          0
          • J JonB
            31 Jan 2020, 13:10

            @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()...

            S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 1 Feb 2020, 16:09 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

            J 1 Reply Last reply 4 Feb 2020, 08:35
            1
            • S SGaist
              1 Feb 2020, 16:09

              @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.

              J Offline
              J Offline
              JonB
              wrote on 4 Feb 2020, 08:35 last edited by JonB 2 Apr 2020, 08:37
              #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

              6/6

              4 Feb 2020, 08:35

              • Login

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