lundi 26 novembre 2018

QComboBox has unrelated behavior with QMessageBox

On a user interface it is possible to upload images on a QGraphicScene using a QPushButton. Additionally on the same interface I have a QCombobox that is doing some operations on the images once they are uploaded. I am setting the user interface so that if I try to use the combobox before any image is uploaded, a QMessage warning pops up telling the user to upload images. It almost works, the issue is that it resets the QCombobox but asks again to upload images. I think it is entering two times in the cycle and I have been struggling in correcting the error.

To recap: I open the interface, try to use the ComboBox; there are no images uploaded and the QMessageBox pops up telling the user to upload images; the Combobox autoresets on the initial value [which in my case is called "Chose operations"] but now another QMessageBox pops up asking the same instead of one time only.

Below the part of the code I think it causing this: mainwindow.cpp

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    ui->leftPreview->setText("<b>No Image Set!</b>");

    points.clear();
    currentSelection = -1; // used to detect if images have been uploaded on QListWidget
}


void MainWindow::on_primarySubComboBoxLeft_currentIndexChanged(const QString &arg1)
{
    if(currentSelection < 0) {
        QMessageBox::information(this, "Option not allowed yet", "Please upload images before using this selection");
        ui->primarySubComboBoxLeft->setCurrentText("Primary Substrate");
        return;
    } else {
       selections[currentSelection]->setPrimarySubText(arg1);
       selections[currentSelection]->updateLabelText();
    }
}

mainwindow.h

private:
    Ui::MainWindow *ui;
    MGraphicsScene* leftScene;

    QList<DataRegion*> selections;
    int currentSelection;

I think it is entering in the loop twice but I am not sure how to solve this issue. Thanks for any advice.

Aucun commentaire:

Enregistrer un commentaire