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. QPushButton editable by user
Forum Update on Monday, May 27th 2025

QPushButton editable by user

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 6 Posters 1.7k Views
  • 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.
  • E Offline
    E Offline
    enim
    wrote on last edited by VRonin
    #1

    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

    J.HilkJ 1 Reply Last reply
    0
    • E enim

      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

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      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.


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        What is your use case for that kind of need ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1
        • E Offline
          E Offline
          enim
          wrote on last edited by
          #4

          @SGaist i want to change the name with one click and with right click i want to execute a method

          jsulmJ JonBJ 2 Replies Last reply
          0
          • E enim

            @SGaist i want to change the name with one click and with right click i want to execute a method

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @enim It is not intuitive at all to use right mouse-button instead of left mouse-button to click on a button...

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            3
            • E Offline
              E Offline
              enim
              wrote on last edited by
              #6

              @jsulm thats right but when i change the click options i have the same Problem ;-)

              mrjjM 1 Reply Last reply
              0
              • E enim

                @jsulm thats right but when i change the click options i have the same Problem ;-)

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @enim
                why not just have an QLineEdit and a button for execute ?
                so user type in line edit and click execute to run it ?

                1 Reply Last reply
                0
                • J.HilkJ Offline
                  J.HilkJ Offline
                  J.Hilk
                  Moderators
                  wrote on last edited by
                  #8

                  or, a better option than my first post,

                  Subclass QLineEdit, set Editable to false,
                  implement the virtual functions virtual void mousePressEvent(QMouseEvent *e) and virtual void mouseReleaseEvent(QMouseEvent *e)

                  from those you can emit your own pressed(), released() and clicked() signals, and make the QLineEdit editable when rightclicked upon.


                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                  Q: What's that?
                  A: It's blue light.
                  Q: What does it do?
                  A: It turns blue.

                  1 Reply Last reply
                  1
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    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.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    3
                    • E enim

                      @SGaist i want to change the name with one click and with right click i want to execute a method

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by
                      #10

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

                      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