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

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 322 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.
  • S Offline
    S Offline
    smolram
    wrote on 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.

    jsulmJ 1 Reply Last reply
    0
    • S smolram

      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.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on 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 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.

        jsulmJ 1 Reply Last reply
        0
        • S smolram

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

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on 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

          • Login

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