Make a label editable after clicking on it. How?
-
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.
-
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...
-
To see if there are better alternatives could you tell us why are you trying to do this please?
-
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! -
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).
-
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).
-
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.
-
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?
-
I agreed with Andre. That way you can have several groups under the same view (if you need them).
-
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!