How to draw QLineEdit over top of QLabel?
-
I'm trying to implement that effect you see in some programs where you double click on a label and it temporarily changes into a line edit tool that lets you change the text.
In one Java program I looked at, they do it by creating a new (Java equivalent of) QLineEdit widget and placing it over top of the label. When the user presses Enter, Esc or clicks away from it, they delete it again. I was wondering if I might be able to do something similar with Qt, and if so how I could get Qt to place my QLineEdit so it looks like it's in front of my QLabel?
My purpose in all this is to create a control that acts similarly to a tree widget. I don't want to use the QTreeWidget because I'm doing some special handling for selection and drag and drop.
-
Hi,
What special handling are you doing that makes you implement your own tree widget ?
-
@kitfox hi,
I would say you have 2 easy ways to archive your goal1 use a QStackedWidget, and place the Laber on one page and the LineEdit on the other
2 use QGridLayout, the addWidget function lets you stack widgets on top of each other, inside one cell.
-
Do you want the QLabel to be visible behind the QLineEdit ? If yes, then you need to QLabel and QLineEdit as parent & child.
If you don't care about the QLabel to visible when you click on it, as suggested by the @J-Hilk , you can use QStackedWidget. It is ideal solution.