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(toggled) setenabled(false) set to actual state ...
QtWS25 Last Chance

QPushbutton(toggled) setenabled(false) set to actual state ...

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 4 Posters 5.4k 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.
  • gfxxG Offline
    gfxxG Offline
    gfxx
    wrote on last edited by
    #1

    As the title, I have a Qpushbutton->setcheckable(true) ... in some part of my code I need to have it Qpushbutton->setEnabled(false) ..... but if It is true/down state and set it setEnabled(false) at successive touch It go to Up/false state .... I need the state to be frozen until I return it to setEnabled(true)..

    is possible these ... how?

    regards
    Giorgio

    bkt

    1 Reply Last reply
    0
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on last edited by
      #2

      hi gfxx,

      Could you show us the relevant code? especially the connects from the pushbutton.
      You might need to use disconnect

      Eddy

      Qt Certified Specialist
      www.edalsolutions.be

      1 Reply Last reply
      0
      • gfxxG Offline
        gfxxG Offline
        gfxx
        wrote on last edited by gfxx
        #3
        MainWindow::MainWindow(QWidget *parent) :
            QMainWindow(parent),
            ui(new Ui::MainWindow)
        {
            ui->setupUi(this);
        
        /**** stupid code****/
        
        connect(ui->zr, SIGNAL(toggled(bool)), this, SLOT(onemyvoid(bool)));
        
        
        }
        /**in my void (different from onemyvoid) on mainwindows*******/
            case 6:
                if(startZeroFalg){StartWaitingUpdate(StZero, StrZero); qDebug() << "zero gui 6: " << StrZero;}
                break;
            case 12:
                if(startZeroFalg){StartWaitingUpdate(ZeroTestint, StrZero); qDebug() << "zero gui 7: " << StrZero;}
                startZeroFalg = false;
                QTimer::singleShot(150, [=]{ emit EnableZeroGuiTh(false); });
                QTimer::singleShot(1000, [=]{  emit makineStat_R(k::st_is_home_6);  ui->zr->setEnabled(false);  });  /********* at these point the button is pressed, but after these if touch over the button It unpressed (because is the natural setenabled(false) state???****so I try to insert the bottom row at these moment******/
                ui->disconnect(); /******* after these the connection row is still valid if setenabled(true) again??******/
                break;
            default:
                break;
            }
        }
        

        regads
        giorgio

        bkt

        gfxxG 1 Reply Last reply
        0
        • gfxxG gfxx
          MainWindow::MainWindow(QWidget *parent) :
              QMainWindow(parent),
              ui(new Ui::MainWindow)
          {
              ui->setupUi(this);
          
          /**** stupid code****/
          
          connect(ui->zr, SIGNAL(toggled(bool)), this, SLOT(onemyvoid(bool)));
          
          
          }
          /**in my void (different from onemyvoid) on mainwindows*******/
              case 6:
                  if(startZeroFalg){StartWaitingUpdate(StZero, StrZero); qDebug() << "zero gui 6: " << StrZero;}
                  break;
              case 12:
                  if(startZeroFalg){StartWaitingUpdate(ZeroTestint, StrZero); qDebug() << "zero gui 7: " << StrZero;}
                  startZeroFalg = false;
                  QTimer::singleShot(150, [=]{ emit EnableZeroGuiTh(false); });
                  QTimer::singleShot(1000, [=]{  emit makineStat_R(k::st_is_home_6);  ui->zr->setEnabled(false);  });  /********* at these point the button is pressed, but after these if touch over the button It unpressed (because is the natural setenabled(false) state???****so I try to insert the bottom row at these moment******/
                  ui->disconnect(); /******* after these the connection row is still valid if setenabled(true) again??******/
                  break;
              default:
                  break;
              }
          }
          

          regads
          giorgio

          gfxxG Offline
          gfxxG Offline
          gfxx
          wrote on last edited by
          #4

          @gfxx no these not solve ... the button return to off state .... so at moment I create a trasparent label that enable end disable over the interesting button ... so is not possible phisically press the button .... but is not a good solution.

          regards
          giorgio

          bkt

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

            Hi,

            Can you re-create that situation with a minimal code sample ?

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

            gfxxG 1 Reply Last reply
            0
            • SGaistS SGaist

              Hi,

              Can you re-create that situation with a minimal code sample ?

              gfxxG Offline
              gfxxG Offline
              gfxx
              wrote on last edited by
              #6

              @SGaist ```
              MainWindow::MainWindow(QWidget *parent) :
              QMainWindow(parent),
              ui(new Ui::MainWindow)
              {
              ui->setupUi(this);

              /**** stupid code****/

              startZeroFalg = true;

              connect(ui->zr, SIGNAL(toggled(bool)), this, SLOT(onemyvoid(bool)));
              connect(this, SIGNAL(Signalminimalcase0(int, QString), this, SLOT(minimalcase(int, QString)));
              connect(this, SIGNAL(Signalminimalcase1(int, QString), this, SLOT(minimalcase(int, QString)));
              connect(this, SIGNAL(Signalminimalcase2(int, QString), this, SLOT(minimalcase(int, QString)));

              /***** end so on****/

              connect(this, SIGNAL(Signalminimalcase12(int, QString), this, SLOT(minimalcase(int)));

              }
              /in my void (different from onemyvoid) on mainwindows*****/
              void Mainwindows::minimalcase(int StZero, QString StrZero)
              {

              switch(StZero){

              case 0:
                     if(startZeroFalg){ StartWaitingUpdate(StZero, StrZero); 
                     firstvoid();
              

              /****** all other case /
              case 6:
              if(startZeroFalg){StartWaitingUpdate(StZero, StrZero); qDebug() << "zero gui 6: " << StrZero;}
              voidsix();
              break;
              case 12:
              if(startZeroFalg){StartWaitingUpdate(ZeroTestint, StrZero); qDebug() << "zero gui 7: " << StrZero;}
              startZeroFalg = false;
              QTimer::singleShot(150, [=]{ emit EnableZeroGuiTh(false); });
              QTimer::singleShot(1000, [=]{ emit makineStat_R(k::st_is_home_6); ui->zr->setEnabled(false); }); /
              **** at these point the button is pressed, but after these if touch over the button It unpressed (because is the natural setenabled(false) state???so I try to insert the bottom row at these moment**/
              ui->disconnect(); /******* after these the connection row is still valid if setenabled(true) again??******/
              break;
              default:
              break;
              }
              }

              void Mainwindows:onemyvoid(bool mybool)
              {
              if(mybool){
              /**** some stuff***/
              emit Siganlminimalcase0(0, customQString);
              }
              }

              
              
              So ui->zr call minimalcase for first time with value "0" and custom QString, case:0 -> call firstvoid() that similary of onemyvoid do some stuff plus emit Signalminimalcase1(1, customQString2)... case:1 call secondvoid() that similary to firstvoid do some stuff + emit signal and so on..... sixvoid do some stuff and emit Signalminimalcase12(12, customQString12).... no other complicate things .... so toglle ui->zr is equal to call a list of void in some sequence .... at the end of list I need ui->zr is setEnabled(false) .... and these happens ... but if press the button these change one time state without emit any type of signal, because is setEnable(false) ... this is right .... but the image of button change ... NOT NEED THESE ....
              
              so or I make sometighs wrong ... or I must sub-class pushbutton for have these result.
              
              regards
              giorgio

              bkt

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

                That's not a minimal code sample. Nobody can re-create and test your problem with that.

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

                gfxxG 1 Reply Last reply
                3
                • SGaistS SGaist

                  That's not a minimal code sample. Nobody can re-create and test your problem with that.

                  gfxxG Offline
                  gfxxG Offline
                  gfxx
                  wrote on last edited by
                  #8

                  @SGaist ha ok not understand these ...sorry .. last night not sleep at all ... Later if I can access that pc I'll do one more complete thing.

                  regards
                  giorgio

                  bkt

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

                    On a side note, you should really take a bit more care with your comments. Having "stupid code" written all over the place doesn't inspire confidence nor motivates to read that code.

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

                    gfxxG 1 Reply Last reply
                    1
                    • SGaistS SGaist

                      On a side note, you should really take a bit more care with your comments. Having "stupid code" written all over the place doesn't inspire confidence nor motivates to read that code.

                      gfxxG Offline
                      gfxxG Offline
                      gfxx
                      wrote on last edited by
                      #10

                      @SGaist said in QPushbutton(toggled) setenabled(false) set to actual state ...:

                      On a side note, you should really take a bit more care with your comments. Having "stupid code" written all over the place doesn't inspire confidence nor motivates to read that code.

                      Thanks A lot of your note, I have no confidence in these aspects of things ... what do I suggest to put? "Foo, foo" are the most suitable words?

                      any how .... Controlling my code and try to reply the situation in one more simple ...

                      #include "mainwindow.h"
                      #include "ui_mainwindow.h"
                      #include <QDebug>
                      #include <QTime>
                      #include <QTimer>
                      #include <QTimerEvent>
                      
                      MainWindow::MainWindow(QWidget *parent) :
                          QMainWindow(parent),
                          ui(new Ui::MainWindow)
                      {
                          ui->setupUi(this);
                      
                          connect(ui->pushButton, SIGNAL(toggled(bool)), this, SLOT(presstoggle(bool)));
                          connect(ui->pushButton_2, SIGNAL(toggled(bool)), this, SLOT(callenabled(bool)));
                          connect(this, SIGNAL(callnumber(int)), this, SLOT(calldisable(int)));
                      }
                      
                      MainWindow::~MainWindow()
                      {
                          delete ui;
                      }
                      
                      
                      void MainWindow::presstoggle(bool pt)
                      {
                          if(pt){
                              QTimer::singleShot(200, [=]{ emit callnumber(10); });
                          }
                          else{
                              QTimer::singleShot(200, [=]{ emit callnumber(0); });
                          }
                      }
                      
                      void MainWindow::callenabled(bool cl)
                      {
                          if(cl){
                              ui->pushButton->setEnabled(true);
                          }
                      
                      }
                      
                      void MainWindow::calldisable(int cd)
                      {
                          switch (cd) {
                          case 0:
                              qDebug() << "the pushbutton emit 0 value: " << cd;
                              break;
                          case 10:
                              qDebug() << "the pushbutton emit 10 value: " << cd;
                              QTimer::singleShot(1400, [=]{ ui->pushButton->setEnabled(false); });
                              //ui->pushButton->setEnabled(false);
                              break;
                          default:
                              qDebug() << "the pushbutton emit ?? value: " << cd;
                              break;
                          }
                      }
                      
                      

                      In these case all work fine ... So I think I've jumped a few steps that will be the real cause of the guileless behavior of the gui .... I have to check but maybe I make a call to something that does not end right away ... but only after the button has, unknowingly, Changed state .... better control ... if I can not find anything I will go to write it ... if I understand the cause I will write it the same .... thanks for the advice ... I have the whole way up before I become A decent programmer ... so you want to excuse my roughness.

                      giorgio

                      bkt

                      gfxxG 1 Reply Last reply
                      0
                      • gfxxG gfxx

                        @SGaist said in QPushbutton(toggled) setenabled(false) set to actual state ...:

                        On a side note, you should really take a bit more care with your comments. Having "stupid code" written all over the place doesn't inspire confidence nor motivates to read that code.

                        Thanks A lot of your note, I have no confidence in these aspects of things ... what do I suggest to put? "Foo, foo" are the most suitable words?

                        any how .... Controlling my code and try to reply the situation in one more simple ...

                        #include "mainwindow.h"
                        #include "ui_mainwindow.h"
                        #include <QDebug>
                        #include <QTime>
                        #include <QTimer>
                        #include <QTimerEvent>
                        
                        MainWindow::MainWindow(QWidget *parent) :
                            QMainWindow(parent),
                            ui(new Ui::MainWindow)
                        {
                            ui->setupUi(this);
                        
                            connect(ui->pushButton, SIGNAL(toggled(bool)), this, SLOT(presstoggle(bool)));
                            connect(ui->pushButton_2, SIGNAL(toggled(bool)), this, SLOT(callenabled(bool)));
                            connect(this, SIGNAL(callnumber(int)), this, SLOT(calldisable(int)));
                        }
                        
                        MainWindow::~MainWindow()
                        {
                            delete ui;
                        }
                        
                        
                        void MainWindow::presstoggle(bool pt)
                        {
                            if(pt){
                                QTimer::singleShot(200, [=]{ emit callnumber(10); });
                            }
                            else{
                                QTimer::singleShot(200, [=]{ emit callnumber(0); });
                            }
                        }
                        
                        void MainWindow::callenabled(bool cl)
                        {
                            if(cl){
                                ui->pushButton->setEnabled(true);
                            }
                        
                        }
                        
                        void MainWindow::calldisable(int cd)
                        {
                            switch (cd) {
                            case 0:
                                qDebug() << "the pushbutton emit 0 value: " << cd;
                                break;
                            case 10:
                                qDebug() << "the pushbutton emit 10 value: " << cd;
                                QTimer::singleShot(1400, [=]{ ui->pushButton->setEnabled(false); });
                                //ui->pushButton->setEnabled(false);
                                break;
                            default:
                                qDebug() << "the pushbutton emit ?? value: " << cd;
                                break;
                            }
                        }
                        
                        

                        In these case all work fine ... So I think I've jumped a few steps that will be the real cause of the guileless behavior of the gui .... I have to check but maybe I make a call to something that does not end right away ... but only after the button has, unknowingly, Changed state .... better control ... if I can not find anything I will go to write it ... if I understand the cause I will write it the same .... thanks for the advice ... I have the whole way up before I become A decent programmer ... so you want to excuse my roughness.

                        giorgio

                        gfxxG Offline
                        gfxxG Offline
                        gfxx
                        wrote on last edited by
                        #11

                        @all ... long story short: mine error ... I' have not evaluate the signal came from a QThred ... these signal update the state of machinery and therefore also updates the status of the gui ... in these way:

                        #include "mainwindow.h"
                        #include "ui_mainwindow.h"
                        #include <QDebug>
                        #include <QTime>
                        #include <QTimer>
                        #include <QTimerEvent>
                        #include <QThread>
                        #include "Jo.h"
                        
                        MainWindow::MainWindow(QWidget *parent) :
                            QMainWindow(parent),
                            ui(new Ui::MainWindow)
                        {
                            ui->setupUi(this);
                            
                            mThrd = new Jo(this);
                            connect(mThrd, SIGNAL(bool)), this, SLOT(vst(bool)), Qt::QueuedConnection);
                            mThrd.start();
                        
                            connect(ui->pushButton, SIGNAL(toggled(bool)), this, SLOT(presstoggle(bool)));
                            connect(ui->pushButton_2, SIGNAL(toggled(bool)), this, SLOT(callenabled(bool)));
                            connect(this, SIGNAL(callnumber(int)), this, SLOT(calldisable(int)));
                            
                            
                        }
                        
                        MainWindow::~MainWindow()
                        {
                            delete ui;
                        }
                        
                        
                        void MainWindow::presstoggle(bool pt)
                        {
                            if(pt){
                                QTimer::singleShot(200, [=]{ emit callnumber(10); });
                            }
                            else{
                                QTimer::singleShot(200, [=]{ emit callnumber(0); });
                            }
                        }
                        
                        void MainWindow::callenabled(bool cl)
                        {
                            if(cl){
                                ui->pushButton->setEnabled(true);
                            }
                        
                        }
                        
                        void MainWindow::calldisable(int cd)
                        {
                            switch (cd) {
                            case 0:
                                qDebug() << "the pushbutton emit 0 value: " << cd;
                                break;
                            case 10:
                                qDebug() << "the pushbutton emit 10 value: " << cd;
                                QTimer::singleShot(1400, [=]{ ui->pushButton->setEnabled(false); });
                                //ui->pushButton->setEnabled(false);
                                break;
                            default:
                                qDebug() << "the pushbutton emit ?? value: " << cd;
                                break;
                            }
                        }
                        
                        void MainWindow::vst(bool state)
                        {
                            if(state){
                                ui->pushButton->setChecked(true);
                                ui->pushButton->setEnabled(false); /*** added code ****/
                                qDebug() << "vst TRUE setcheched true";;
                            }
                            else{
                                ui->pushButton->setChecked(false);
                                ui->pushButton->setEnabled(true); /*** added code ****/
                                qDebug() << "vst FALSE setcheched false";
                            }
                        
                        
                        }
                        

                        sorry not remember these part of my code, because I write it more than 2 mounth ago .... any how today I insert the row indicate on "/*** added code ***/ and all works fine.

                        Probabily the previous signal ui->pushbutton->setEnabled(false) arrive in same time of state (void vst) so the button was Disable & setSheched so Disable signal was ignore for some reason until Qthread release it (in setchecked(false) mode).

                        But more expert in signal & slot can learn me the more propabily causes of these ...But more experienced people than me can teach me a more adhering cause to the reality of the problem.

                        giorgio

                        bkt

                        1 Reply Last reply
                        0
                        • Puppy BearP Offline
                          Puppy BearP Offline
                          Puppy Bear
                          wrote on last edited by
                          #12

                          if(condition)
                          d->m_CheckBox->blockSignals(true);

                          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