简体   繁体   中英

How to remove all buttons from QInputDialog

I have an input dialogue with combo-box, to choose between 2 options.

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();
    }
}

How to remove buttons from QInputDialog ? I am using 'NoButtons' flag but still it isn't helping.Kindly suggest any other approach.

QInputDialog::getItem method is a static method . In other words, it has nothing to do with your instantiated object (ie inputDialog ). You should use the following code snippet instead.

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();

Result:

在此处输入图片说明

Once the dialog is closed, you can use QInputDialog::textValue() method to retrieve user's choice.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM