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 check function is not working well
Forum Updated to NodeBB v4.3 + New Features

QPushButton check function is not working well

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.7k 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.
  • KaguroK Offline
    KaguroK Offline
    Kaguro
    wrote on last edited by
    #1

    Hi Guys!
    I dont know where is my mistakes, but I create a QPushbutton and add cilicked event to it. In the cilicked event I checked if the button is checked then i write to debug something and set the pushbutton state to unchecked. And when I clicked the button again the button is checked again... so always checked when i clicked.
    So the button:

    ui->setupUi(this);
    ui->pushButton->setCheckable(true);
    ...
    

    And the click event:

    void MainWindow::on_pushButton_clicked()
    {
        if(ui->pushButton->isChecked())
        {
            qDebug()<<"Checked";
            ui->pushButton->setChecked(false);
        }
        else
        {
            qDebug()<<"UnChecked";
            ui->pushButton->setChecked(true);
        }
    }
    

    The message is always Checked.
    Where is my mistake?
    Thanks your help!

    M 1 Reply Last reply
    0
    • KaguroK Kaguro

      Hi Guys!
      I dont know where is my mistakes, but I create a QPushbutton and add cilicked event to it. In the cilicked event I checked if the button is checked then i write to debug something and set the pushbutton state to unchecked. And when I clicked the button again the button is checked again... so always checked when i clicked.
      So the button:

      ui->setupUi(this);
      ui->pushButton->setCheckable(true);
      ...
      

      And the click event:

      void MainWindow::on_pushButton_clicked()
      {
          if(ui->pushButton->isChecked())
          {
              qDebug()<<"Checked";
              ui->pushButton->setChecked(false);
          }
          else
          {
              qDebug()<<"UnChecked";
              ui->pushButton->setChecked(true);
          }
      }
      

      The message is always Checked.
      Where is my mistake?
      Thanks your help!

      M Offline
      M Offline
      mpergand
      wrote on last edited by mpergand
      #2

      @Kaguro

      Hi,

      When you click on the button the state changes,
      if it checked you set it to false,
      so it will be checked again each time you click on it.

      KaguroK 1 Reply Last reply
      3
      • M mpergand

        @Kaguro

        Hi,

        When you click on the button the state changes,
        if it checked you set it to false,
        so it will be checked again each time you click on it.

        KaguroK Offline
        KaguroK Offline
        Kaguro
        wrote on last edited by
        #3

        @mpergand Oh I see! Okay i was retarded! Thank you!!!

        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