Solved QPushButton editable by user
-
Hi,
i want to make a Pushbutton editable by clicking on it. But i dont want to open a text field. I want to Highlight the text of the button by clicking on it and then the user can Change the Name.Do you have any idea, how i can realize it
thank you in advance
[VRonin] Linking German post https://forum.qt.io/topic/95389/qpushbutton-bearbeitbar
-
hi @enim
there's no easy way to do this, that I know of.
You'll have to subclass for example QLineEdit add a QPushButton to that and manage the size/position of the child pushbutton via QResizeEvent. You'll than need some logic to switch between LineEdit and PushButton and some good StyleSheet management to make it seem like one Item.
-
Hi,
What is your use case for that kind of need ?
-
@SGaist i want to change the name with one click and with right click i want to execute a method
-
@enim It is not intuitive at all to use right mouse-button instead of left mouse-button to click on a button...
-
@jsulm thats right but when i change the click options i have the same Problem ;-)
-
@enim
why not just have an QLineEdit and a button for execute ?
so user type in line edit and click execute to run it ? -
or, a better option than my first post,
Subclass QLineEdit, set Editable to false,
implement the virtual functionsvirtual void mousePressEvent(QMouseEvent *e)
andvirtual void mouseReleaseEvent(QMouseEvent *e)
from those you can emit your own
pressed()
,released()
andclicked()
signals, and make the QLineEdit editable when rightclicked upon. -
If you really want to be able to change the button name you should rather have a contextual menu that will provide an action for that, then use something like QInputDialog to get the new name and set it on the button.
-
@enim said in QPushButton editable by user:
i want to change the name with one click and with right click i want to execute a method
Follow @SGaist's recommendation in his last post, or what others have suggested.
The important thing is, so that the interface is vaguely what the user might expect, you actually want to make it so the normal left click performs the button's action while the right click is what is used to change its label, not the way round you suggested.