sách gpt4 ăn đã đi

c++ - 输入 SpinBox 时点击默认的 QPushButton

In lại 作者:太空狗 更新时间:2023-10-29 23:02:53 26 4
mua khóa gpt4 giày nike

khi tôi còn QSpinBox 上按 Enter(实际上在每个输入框上)时,我需要提高 QPushButton 的点击信号,但即使我的按钮是默认按钮,以下代码不起作用。

#include 
#include
#include
#include
#include

int main(int argc, char* argv[])
{
QApplication app(argc, argv);

QWidget* window = new QWidget();

QSpinBox* spinbox = new QSpinBox();
QPushButton* button = new QPushButton("Ok");
button->setDefault(true);

QObject::connect(button, &QPushButton::clicked, []()
{
QMessageBox::question(nullptr, "Test", "Quit?", QMessageBox::Yes|QMessageBox::No);
});

QHBoxLayout* layout = new QHBoxLayout();
layout->addWidget(spinbox);
layout->addWidget(button);
window->setLayout(layout);
window->show();

return app.exec();
}

我该如何解决?

câu trả lời hay nhất

您可以在 Qt 文档中看到关于 QPushButton :

The default button behavior is provided only in dialogs

bạn đang sử dụng Tiện ích QWidget 并希望默认按钮行为有效。只需使用 QDialog thay vì Tiện ích QWidget :

QDialog * window = new QDialog();
...

关于c++ - 输入 SpinBox 时点击默认的 QPushButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27193841/

26 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress