gpt4 book ai didi

c++ - 如何从 QInputDialog 中删除所有按钮

转载 作者:行者123 更新时间:2023-11-28 00:00:16 30 4
gpt4 key购买 nike

我有一个带有组合框的输入对话框,可以在 2 个选项之间进行选择。

void MainWindow::on_UpdateCPUAssmblyBtn_clicked()
{
if(!ui->AssemblyCpuSN->toPlainText().toStdString().empty())
{
QStringList items;
items << tr("OUT_FOR_PCB_REPAIR") << tr("PCB_SCRAPPED");

bool ok;
std::string scrapcode="";
QInputDialog* inputDialog = new QInputDialog();
inputDialog->setOption(QInputDialog::NoButtons);

QString item = inputDialog->getItem(NULL ,"Manufacturing Stage",
"Please select the reason for removing the old board :", items, 0,false,
&ok);
if(ok && !item.isEmpty())
scrapcode=item.toStdString();

/* Do something with scrapcode */
}
else
{
QPixmap pix("icons/angry1.png");
mbox->setIconPixmap(pix);
mbox->setWindowTitle("ERROR");
mbox->setText("Disassociation is not successful.CPU SN is empty.");
mbox->show();
}
}

如何从 QInputDialog 中删除按钮?我正在使用“NoButtons”标志,但它仍然没有帮助。请建议任何其他方法。

最佳答案

QInputDialog::getItem 方法是一个 static method .换句话说,它与您的实例化对象(即 inputDialog)无关。您应该改用以下代码片段。

QInputDialog* inputDialog = new QInputDialog();
inputDialog->setOption(QInputDialog::NoButtons);
inputDialog->setComboBoxItems(items);
inputDialog->setWindowTitle("Manufacturing Stage");
inputDialog->setLabelText("Please select the reason for removing the old board :");
inputDialog->show();

结果:

enter image description here

对话框关闭后,您可以使用QInputDialog::textValue() 方法来检索用户的选择。

关于c++ - 如何从 QInputDialog 中删除所有按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39604035/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com