Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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



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



  • what version of Qt and OS do you use?



  • Qt 4.8.4 Windows 7



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



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



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



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



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

    you should not manually call setChecked(bool) method.



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


Log in to reply