Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-95255

After setDefaultAction for a QToolButton and call setChecked, then checked status wrong

    XMLWordPrintable

Details

    • Windows
    • 188d739400e10fc8571bbf2ec86d5cd338b04a5d (qt/qtbase/dev) a72c95bf8b7c31fdd7ff1bd0f1c08dc371b07081 (qt/qtbase/6.2) f3138e9d533d8db723cf6f325ad8f84902a021f1 (qt/qtbase/6.1) 626418ad136e58af01599c17ef999f367f5c0619 (qt/qtbase/6.1)

    Description

      There are two ways to trigger bugs(Code at the buttom)

      First:

      1.run program

      2.click setTrueButton

      3.click toolButton

      then the toolButton's checked status is still true

       

      //out of the program
      MainWindow::on_setTrueButton_clicked() start
      check status: false
      set checked true
      check status: true
      MainWindow::on_setTrueButton_clicked() over
      "MainWindow::on_toolButton_clicked(1)"
      Sender Btn cheacked status: true

       

      Second:

      1.run program

      2.click toolButton

      3.click setFalseButton

      4.click toolButton

      then the toolButton's checked status is still false

      //out of the program
      "MainWindow::on_toolButton_clicked(1)"
      Sender Btn cheacked status: true
      MainWindow::on_setFalseButton_clicked()
      checked status: true
      set checked false
      checked status: false
      MainWindow::on_setFalseButton_clicked() over
      "MainWindow::on_toolButton_clicked(0)"
      Sender Btn cheacked status: false
      
      //Here is the code
      MainWindow::MainWindow(QWidget *parent)
          : QMainWindow(parent)
          , ui(new Ui::MainWindow)
      {
          ui->setupUi(this);
          QAction * a = new QAction(this);
          a->setCheckable(true);
          ui->toolButton->addAction(a);
          ui->toolButton->setDefaultAction(a);
          ui->toolButton->setObjectName("A");
      }
      
      MainWindow::~MainWindow()
      {
          delete ui;
      }
      
      
      void MainWindow::on_toolButton_clicked(bool checked)
      {
          qDebug()<<QString("MainWindow::on_toolButton_clicked(%1)").arg(checked);
          QToolButton *senderBtn = (QToolButton *)sender();
          qDebug()<<"Sender Btn cheacked status:"<<senderBtn->isChecked();
      }
      
      void MainWindow::on_setTrueButton_clicked()
      {
          qDebug()<<"MainWindow::on_setTrueButton_clicked() start";
          qDebug()<<"check status:"<<ui->toolButton->isChecked();
          ui->toolButton->setChecked(true);
          qDebug()<<"set checked true";
          qDebug()<<"check status:"<<ui->toolButton->isChecked();
          qDebug()<<"MainWindow::on_setTrueButton_clicked() over";
      }
      
      void MainWindow::on_setFalseButton_clicked()
      {
          qDebug()<<"MainWindow::on_setFalseButton_clicked()";
          qDebug()<<"checked status:"<<ui->toolButton->isChecked();
          ui->toolButton->setChecked(false);
          qDebug()<<"set checked false";
          qDebug()<<"checked status:"<<ui->toolButton->isChecked();
          qDebug()<<"MainWindow::on_setFalseButton_clicked() over";
      }
      
      
       
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            vhilshei Volker Hilsheimer
            chenghongfeng 程 洪峰
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: