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. Enable a button after it has been disabled

Enable a button after it has been disabled

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 1.3k 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.
  • J Offline
    J Offline
    jkprog
    wrote on 1 Jul 2017, 20:46 last edited by
    #1

    Hi, I have more than 60 pushbuttons in my project. For each of the buttons, if the user pressed it for 5seconds or more than the button is disabled. Then if the user presses that same button for 5 seconds, the button is enabled.
    So far I have achieved the disabled part, but I am having trouble in enabling the disabled button.
    I have used two timers, one for enabling and the other for disabling the button.

    My code is:

     timer = new QTimer(this);
        connect(timer,SIGNAL(timeout()),this,SLOT(disable_button()) );
    
        timer1 = new QTimer(this);
        connect(timer1,SIGNAL(timeout()), this, SLOT(enable_button()) );
    
    void MainWindow::on_Btn_clicked(bool checked)
    {
        if(checked == true)
        {
            timer->start(5000);
            qDebug() << 1;
        }
        if(checked == false)
        {
            qDebug() << 0;
    
        }
    }
    
    void MainWindow::disable_button()
    {
        ui->Btn->setDisabled(true);
    }
    
    void MainWindow::enable_button()
    {
        
        if (ui->Btn->setDisabled(true))
        {
            ui->Btn->setEnabled(true);
        }
    
    }
    
    
    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 1 Jul 2017, 20:58 last edited by mrjj 7 Jan 2017, 21:02
      #2

      Hi
      When you disable a widget. it will not get any events. Or at least not click ones.

      So when a button is disabled it means that it should not emit a signal if clicked ?
      and to unlock it, user should hold for 5 secs?

      I think this would be easier with a custom widget that internally would keep track of locked/unlocked status by long press.

      If unlocked and user just click and release fast. will it then call its function ?
      So it can hold to lock/unlock and if unlocked, it will call its clicked slot ?

      1 Reply Last reply
      3
      • ? Offline
        ? Offline
        A Former User
        wrote on 1 Jul 2017, 20:59 last edited by
        #3

        What @mrjj said. You can't press a disabled button, that's the whole point of disabling it.

        1 Reply Last reply
        3

        1/3

        1 Jul 2017, 20:46

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved