qt c++QPushbutton按下状态怎么获取
使用isChecked()函数来获取QPushButton的按下状态。该函数返回一个bool类型的值,如果按钮被按下,返回true,否则返回false。
示例代码如下:
#include <QApplication>
#include <QPushButton>
#include <QDebug>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QPushButton button("Button");
QObject::connect(&button, &QPushButton::clicked, [&button]() {
bool isChecked = button.isChecked();
if (isChecked) {
qDebug() << "Button is checked";
} else {
qDebug() << "Button is not checked";
}
});
button.show();
return a.exec();
}
运行该程序,当按钮被按下时,会输出"Button is checked",当按钮没有被按下时,会输出"Button is not checked"
原文地址: http://www.cveoy.top/t/topic/iQtJ 著作权归作者所有。请勿转载和采集!