Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to create a function to choose a specific Label from many and edit it
QtWS25 Last Chance

How to create a function to choose a specific Label from many and edit it

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 293 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.
  • S Offline
    S Offline
    smolram
    wrote on 25 May 2020, 06:15 last edited by
    #1

    I am trying to come up with a code that will simulate the state of Arduino ports. I have 8 labels, one per bit. I want to create a function that will allow me to choose one of the labels specifically and set it to either high or low and display it in the mainwindow.

    J 1 Reply Last reply 25 May 2020, 06:20
    0
    • S smolram
      25 May 2020, 06:15

      I am trying to come up with a code that will simulate the state of Arduino ports. I have 8 labels, one per bit. I want to create a function that will allow me to choose one of the labels specifically and set it to either high or low and display it in the mainwindow.

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 25 May 2020, 06:20 last edited by
      #2

      @smolram What exactly is the problem? It is really not clear from your post.
      You already have 8 labels, right? Do you show them already in your UI?
      Or do you want to show one of these 8 labels? In this case why do you need 8 labels if you only show one?

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

      1 Reply Last reply
      0
      • S Offline
        S Offline
        smolram
        wrote on 25 May 2020, 06:25 last edited by
        #3

        @jsulm I already have the 8 labels created and shown in my UI. I am just trying to come up with a function the will edit one specific label out of the 8. Lets say I want to change Lable_3 to say High, so I want a function that will be able to choose Label_3 and set it to High. I know how to edit the labels I just don't know how to create a function to choose the label I want to and edit it. But I will be showing all 8 at the same time, but the function would be a quick way to choose one label and change the text.

        J 1 Reply Last reply 25 May 2020, 06:32
        0
        • S smolram
          25 May 2020, 06:25

          @jsulm I already have the 8 labels created and shown in my UI. I am just trying to come up with a function the will edit one specific label out of the 8. Lets say I want to change Lable_3 to say High, so I want a function that will be able to choose Label_3 and set it to High. I know how to edit the labels I just don't know how to create a function to choose the label I want to and edit it. But I will be showing all 8 at the same time, but the function would be a quick way to choose one label and change the text.

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 25 May 2020, 06:32 last edited by
          #4

          @smolram Well, write a method which takes an index (0-7). Put pointers to your labels into a vector:

          QVector<QLabel*> labels;
          ...
          labels[0] = Label_0;
          ...
          
          void MyClass::editLabel(int index)
          {
              // Check the index first - it should be in range 0..7
              labels[index]->...
          }
          

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

          1 Reply Last reply
          4

          1/4

          25 May 2020, 06:15

          • Login

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