要将按钮设置为按下状态,需要使用QPushButton类的setCheckable()方法将按钮设置为可选中状态,并使用setChecked()方法将按钮设置为选中状态。
以下是一个示例代码:
#include <QtWidgets>int main(int argc, char *argv[]){QApplication app(argc, argv);// 创建一个窗口QWidget window;// 创建一个按钮QPushButton button("按钮", &window);// 设置按钮为可选中状态button.setCheckable(true);// 设置按钮为选中状态button.setChecked(true);// 显示窗口window.show();return app.exec();}在上面的示例中,按钮在创建时被设置为可选中状态,然后使用setChecked()方法将其设置为选中状态。在按钮被选中时,按钮会显示为按下状态。

