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. Make a label editable after clicking on it. How?
Qt 6.11 is out! See what's new in the release blog

Make a label editable after clicking on it. How?

Scheduled Pinned Locked Moved General and Desktop
12 Posts 5 Posters 19.7k 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.
  • A Offline
    A Offline
    andre
    wrote on last edited by
    #3

    I concur with Keith, UI wise it seems a bit weird.

    Still, I think there are solutions. One way might be to use an actual QLineEdit the whole time, but use some clever CSS to style the line edit to look like a label when it does not have focus.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #4

      Another solution would be to use a QStackedWidget with a label and a QLIneEdit. Clicking on the label changes the visible widget and ending editing also. You could create a custom widget out of this.

      But for me, it also seams strange for a UI, I would normally never click on a label...

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        ZapB
        wrote on last edited by
        #5

        To see if there are better alternatives could you tell us why are you trying to do this please?

        Nokia Certified Qt Specialist
        Interested in hearing about Qt related work

        1 Reply Last reply
        0
        • B Offline
          B Offline
          Bekos
          wrote on last edited by
          #6

          Thank you guys for all your answers! I will try multiple solutions to see what fits best (and if I can actually implement them :P).
          @ZapB: I have a OpenGL application with a dock widget. On the dock widget I have a QListWidget called state list. Each item of the list represents a state of the application. I can add,remove and modify states. So, I want to have a Title for the state list and be able to change/edit it.
          Thanks again!

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            ZapB
            wrote on last edited by
            #7

            Can you not just use editable items in your QListWidget then? The view paints the items but then when you trigger the editing mode, the delegate creates a suitable editor widget for you (QLineEdit in the case of simple text).

            Nokia Certified Qt Specialist
            Interested in hearing about Qt related work

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #8

              If you have a QListWidget already, then you don't need to make editable labels. The items in an item view (which QListWidget is) are already editable if you just set the right flags in the model (in your case in the QListWidgetItem).

              1 Reply Last reply
              0
              • B Offline
                B Offline
                Bekos
                wrote on last edited by
                #9

                Thanks for the replies guys. I am sorry I didn't describe my problem very good. This editable label i want to create is for the entire list. (it is the title of the list) Of course when I want to rename a single state I edit the QListWidgetItems. The editable label I want is for the whole thing.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andre
                  wrote on last edited by
                  #10

                  Just a thought: wouldn't it make sense to use a QTreeWidget instead, and then instead of using a separate label, use a root item that you can rename instead?

                  1 Reply Last reply
                  0
                  • Z Offline
                    Z Offline
                    ZapB
                    wrote on last edited by
                    #11

                    I agreed with Andre. That way you can have several groups under the same view (if you need them).

                    Nokia Certified Qt Specialist
                    Interested in hearing about Qt related work

                    1 Reply Last reply
                    0
                    • B Offline
                      B Offline
                      Bekos
                      wrote on last edited by
                      #12

                      Sorry for the delayed response. Oh yeah. I see your point and you are indeed right. Unfortunately, I can not do that at the moment because I will need to change a lot of stuff and I am not the only one working on this project. But I will consider this on the next update of our application. For now, as Andre suggested, I inherit from QLineEdit my own class and I do some stylesheet "magic". It actually works fine. But yet, I find the QTreeWidget solution a better idea. I will give it a go soon!
                      Thank you all guys!
                      Cheers!

                      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