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. [Solved] How to Toggle qpushbutton name
QtWS25 Last Chance

[Solved] How to Toggle qpushbutton name

Scheduled Pinned Locked Moved General and Desktop
10 Posts 2 Posters 2.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.
  • H Offline
    H Offline
    herculis
    wrote on last edited by
    #1

    hello guys i want to toggle qpushbutton name means when i hit the push button once, push button should have name as "add" and when i hit it again it should have sub and when i hit it gain it should show again add.

    How can i do it
    plz help me guys
    Thanks

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

      Hi,

      Use a slot connected to the clicked() signal, or if you are using a checkable button the toggled(bool) signal.

      In the slot, verify the current text and change it accordingly or if your button is checkable, update the name based on whether the button is checked or not.

      [edit: corrected wrong wording]

      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
      0
      • H Offline
        H Offline
        herculis
        wrote on last edited by
        #3

        @addButton = new QPushButton(tr("add"));
        connect(addButton, SIGNAL(clicked()),this, SLOT(slotButtonaddPressed()));

        void abcd:slotButtonaddPressed()
        {
        hideButton->setText(tr("sub"));
        }
        @

        I have done this now when i clicked 3rd time it shows "sub" only i want add when i press 3rd time how can i do that
        thanks

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

          You haven't implemented the "verify the button name" part

          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
          0
          • H Offline
            H Offline
            herculis
            wrote on last edited by
            #5

            verify means
            how can i do it
            Help

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

              Verify means: test what the current QPushButton text is and then set the other one.

              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
              0
              • H Offline
                H Offline
                herculis
                wrote on last edited by
                #7

                with which function i can check the name of pushbutton i know i have to use it in If statement
                Can u give on example related to my one.
                Thanks

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

                  Use the "text":http://qt-project.org/doc/qt-5/qabstractbutton.html#text-prop property

                  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
                  0
                  • H Offline
                    H Offline
                    herculis
                    wrote on last edited by
                    #9

                    @if(addButton->text=="add")
                    {
                    addButton->setText(tr("sub"));
                    }
                    else
                    {
                    addButton->setText(tr("add"));
                    }@
                    i wrote like this but it not working it not building the program

                    1 Reply Last reply
                    0
                    • H Offline
                      H Offline
                      herculis
                      wrote on last edited by
                      #10

                      Thank you very much SGaist it worked
                      Thanks alot

                      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