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 do i make a QToolButton to work similiar to Bold button in text editors?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] How do i make a QToolButton to work similiar to Bold button in text editors?

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 3.0k Views 1 Watching
  • 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.
  • B Offline
    B Offline
    b1gsnak3
    wrote on last edited by
    #1

    How can I make a QToolButton work in a similar fashion to the Bold button in text editing software? I have tried using the setCheckable(true) way, but it worked only for the first press. Afterwards it didn't work anymore.

    Thank you in advance.

    1 Reply Last reply
    0
    • _ Offline
      _ Offline
      _rmn
      wrote on last edited by
      #2

      what version of Qt and OS do you use?

      1 Reply Last reply
      0
      • B Offline
        B Offline
        b1gsnak3
        wrote on last edited by
        #3

        Qt 4.8.4 Windows 7

        1 Reply Last reply
        0
        • K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          @b1snak3
          your thread title is useless. Please change to have something triggering an understanding without opening it.

          Vote the answer(s) that helped you to solve your issue(s)

          1 Reply Last reply
          0
          • _ Offline
            _ Offline
            _rmn
            wrote on last edited by
            #5

            Please, give more details about your problem. May be post some related code

            1 Reply Last reply
            0
            • B Offline
              B Offline
              b1gsnak3
              wrote on last edited by
              #6

              @ callButton = new QToolButton;
              callButton->addAction(callAct);
              mainToolBar->addWidget(callButton);
              callButton->setStyleSheet("QToolButton::menu-indicator{image:none;}");
              callButton->setIcon(QIcon(voiceCallPix));
              callButton->setCheckable(true);
              // Connect
              connect(callButton, SIGNAL(clicked()), this, SLOT(callUser()));

              // the callUser slot
              void PMsgWindow::callUser() {

              callButton->setChecked(true);
                  callAct->setToolTip("End call");
              

              // the 2nd connect for the deactivation of the press
              // this is in the callUser slot
              connect(callButton, SIGNAL(clicked()), this, SLOT(endCall()));

              // the endcall slot
              void PMsgWindow::endCall() {
              callButton->setChecked(false);
              callFrame->hide();
              chatEdit->setMinimumHeight(400);
              }@

              this code works only for the 1st click. then it doesn't react in the same way.

              1 Reply Last reply
              0
              • _ Offline
                _ Offline
                _rmn
                wrote on last edited by
                #7

                do you make @disconnect(callButton, SIGNAL(clicked()), this, SLOT(callUser()));@

                at callUser() slot?

                Also instead of using 2 slots for clicked() signal, you can make one slot e.g.
                @void call(bool checked);@

                and connect clicked(bool) signal to it.

                1 Reply Last reply
                0
                • _ Offline
                  _ Offline
                  _rmn
                  wrote on last edited by
                  #8

                  also with
                  @
                  callButton->setCheckable(true);
                  @

                  you should not manually call setChecked(bool) method.

                  1 Reply Last reply
                  0
                  • B Offline
                    B Offline
                    b1gsnak3
                    wrote on last edited by
                    #9

                    that works, thank you. tried the clicked(bool) earlier but didn't make it to work. the disconnect approach works.

                    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