2016-09-20 2 views
0

Ich habe einen Eingabedialog mit Combo-Box, um zwischen 2 Optionen zu wählen.So entfernen Sie alle Schaltflächen von QInputDialog

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

Wie Schaltflächen aus QInputDialog entfernen? Ich benutze "NoButtons" -Flag, aber es hilft immer noch nicht. Empfehlen Sie bitte einen anderen Ansatz.

Antwort

2

QInputDialog::getItem Methode ist ein static method. Mit anderen Worten, es hat nichts mit Ihrem instanziierten Objekt zu tun (d. H. inputDialog). Sie sollten stattdessen das folgende Code-Snippet verwenden.

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

Ergebnis:

enter image description here

Sobald der Dialog geschlossen wird, können Sie QInputDialog::textValue() Methode der Wahl des Benutzers abzurufen.

+0

Vielen Dank !! – Minion