Unsolved Unable to make a dialog modal and within bounds of GUI
-
Hi. I have the following code.
cupcalibration.cpp (parent)
CupCalibration::CupCalibration(QWidget *parent) : QDialog(parent), ui(new Ui::CupCalibration) { setWindowFlags(Qt::FramelessWindowHint| Qt::WindowSystemMenuHint); ui->setupUi(this); this->move(0, 0); MultiPointCalibration mpCal((QWidget*)this); mpCal.setScreenTitle(tr("Sample Temp Cup")); mpCal.setInitialValues(QList<double>() << 20.0 << 40.0 << 60.0); mpCal.setUnits(QString(QChar(0260)) + "C"); //mpCal.setModal(true); //mpCal.setParent(this); mpCal.setManualMode("Set the water bath to %1"); mpCal.setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint| Qt::WindowSystemMenuHint); mpCal.exec(); }
multipointcalibration.cpp
#define CUSTOM_SETUP_UI ui->setupUi(getMainContentWidget());resizeBaseUI();QMetaObject::connectSlotsByName(this); MultiPointCalibration::MultiPointCalibration(QWidget *parent) : CustomQtDialog(parent), ui(new Ui::MultiPointCalibration) { CUSTOM_SETUP_UI; ui->setupUi(this); this->move(200, 100); this->setWindowFlags(Qt::Dialog | Qt::WindowSystemMenuHint | Qt::FramelessWindowHint); decimalPlaces = 1; connect(ui->listWidget, SIGNAL(editClicked()), this, SLOT(editListItem())); connect(ui->listWidget, SIGNAL(deleteClicked()), this, SLOT(deleteListItem())); // // primary buttons setupButton(BACK_BUTTON, POSITION1); startButton = setupButton(START_BUTTON, POSITION4); // // secondary buttons setupButton(ABORT_BUTTON, POSITION5); // // saveButton is first of all a next button (dont need to set the text here, it will be set later when we run setupMainScreen) saveButton = setupButton(CUSTOM_BUTTON, POSITION8); setPointMode = NORMAL_MODE; verificationMode = false; setDataLabels(tr("Value")); setUnits(""); setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint| Qt::WindowSystemMenuHint); // set these as initial values ui->stackedWidget->setCurrentIndex(PAGE_SELECT); ui->inProgressStackedWidget->setCurrentIndex(IN_PROGRESS_WAITING); ui->statusStackedWidget->setCurrentIndex(IN_PROGRESS_WAITING); ui->referenceEntry->installEventFilter(this); machine = new QStateMachine(this); QState* select = new QState(machine); QState* mainScreen = new QState(machine); QState* running = new QState(mainScreen); QState* workOutNextPoint = new QState(running); QState* aimingForPoint = new QState(running); QState* skippedUserEntersMeasured = new QState(running); QState* userEntersMeasured = new QState(running); QState* calculateStraightLine = new QState(mainScreen); QState* readyForSave = new QState(mainScreen); machine->setInitialState(select); connect(select, SIGNAL(entered()), this, SLOT(showPrimaryButtons())); select->addTransition(startButton, SIGNAL(clicked()), workOutNextPoint); select->assignProperty(ui->stackedWidget, "currentIndex", 0); select->assignProperty(this, "statusBarProgress", 0); select->assignProperty(this, "statusBarMessage", tr("Select points")); select->assignProperty(startButton, "enabled", true); machine->start(); }
multipointclaibration.h
#ifndef MULTIPOINTCALIBRATION_H #define MULTIPOINTCALIBRATION_H #include <QDateTime> #include "CustomQtDialog/Customqtdialog.h" #include "stabilitycriteria.h" class QStateMachine; class QState; namespace Ui { class MultiPointCalibration; } struct CalibrationInfo { QDateTime date; struct CalibrationPoint { double internal; double reference; }; QList<CalibrationPoint> calibrationPoints; double m; double c; }; class MultiPointCalibration : public CustomQtDialog { Q_OBJECT public: explicit MultiPointCalibration(QWidget *parent = 0); ~MultiPointCalibration(); bool eventFilter(QObject *obj, QEvent *event); // set as manual mode - don't set the set point, instead tell the user to set the value of their apparatus to the appropriate setting void setManualMode(QString manualModeMessage); // set as resistance mode - don't set the set point, instead tell the user to change the resistors over void setResistanceMode(QString resistanceModeMessage); // set as verification mode - this affects the last page and the saving only - show each point and the acceptable variation - this mode should work in conjuction with the other modes void setVerificationMode(double allowableVariation); void setInitialValues(QList<double> values, int minimumPoints = 2); void setStabilityCriteria(StabilityCriteria criteria); void setUnits(QString units); // this is the text that will be applied to the labels that show the data // e.g. for a temperature calibration set this as "Temperature" void setDataLabels(QString dataLabels); void setDecimalPlaces(int decimalPlaces); protected: virtual bool savePressed(); virtual QString getAbortMessage() { return tr("Are you sure you want to abort this calibration?"); } private slots: void internalMeaurementReceived(double liveMeasurement); // setup the main calibration screen void setupMainScreen(); // decide what the next point is (if any) void workOutNextPoint(); // start sending the hardware to the next point void setupAim(); // calculate the best fit straightline between all the points void calculateStraightline(); void on_addButton_clicked(); // one of the list items has been requested to be edited void editListItem(); void deleteListItem(); signals: void nextPointReady(); void allPointsComplete(); void readingsStable(); void mathsComplete(); void pointEdited(); // this is to be handled externally to set the set point void requestSetPoint(double setPoint); // handle this in the code to capture the calibration info to be saved void calibrationToSave(CalibrationInfo info); private: Ui::MultiPointCalibration *ui; enum SetPointMode { NORMAL_MODE, MANUAL_MODE, RESISTANCE_MODE } setPointMode; QString setPointModeMessage; bool verificationMode; double verAllowableDifference; QString units; StabilityCriteria criteria; int decimalPlaces; int minimumPoints; QStateMachine* machine; QState* waitingForNextStates[2]; CalibrationInfo calibrationInfo; QPushButton* startButton; QPushButton* saveButton; int currentStage; QList<double> stages; double lastMeasurement; }; #endif // MULTIPOINTCALIBRATION_H
customQtDialog.cpp
#define CUSTOM_SETUP_UI ui->setupUi(getMainContentWidget());resizeBaseUI();QMetaObject::connectSlotsByName(this); CustomQtDialog::CustomQtDialog(QWidget *parent) : QDialog(parent), baseui(new Ui::CustomQtDialog) { baseui->setupUi(this); //originalBaseUiSize = baseui->mainContents->size(); // this->move(0, 0); this->setWindowFlags(Qt::Dialog |Qt::WindowSystemMenuHint |Qt::FramelessWindowHint); qDebug() << this->windowFlags(); // setup default settings handler for this screen - can be changed later by individual screens setupSettingsHandler(Settings::get()); primaryButtonsVisible = true; // keep a reference of the buttons from the ui file as an easy way to access them buttons[0] = baseui->button1; buttons[1] = baseui->button2; buttons[2] = baseui->button3; buttons[3] = baseui->button4; // for the secondary buttons, make them as duplicates of the primary ones for (int i = 0; i < 4; i++) { buttons[i + 4] = new QPushButton(this); buttons[i + 4]->setGeometry(buttons[i]->geometry()); buttonsShown[i] = false; } for (int i = 0; i < 8; i++) buttons[i]->hide(); statusBarTempTimeout = new QTimer(this); statusBarTempTimeout->setSingleShot(true); connect(statusBarTempTimeout, SIGNAL(timeout()), this, SLOT(resetStatusBarText())); permanentStatusBarText = ""; QFile stylesheetFile(":/stylesheet/stylesheet.css"); if (stylesheetFile.open(QFile::ReadOnly)) this->setStyleSheet(stylesheetFile.readAll()); else qDebug() << "ERROR - Cannot open stylesheet.css from genericresources.qrc"; slidePanels = 0; }
What I expect this file to do is to activate a new object (which acts as a page), and for it to be a modal windows, as part of the previously existing windows. However, this object is being created outside of the preexisting windows, despite me setting the flags at
mpCal.setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint| Qt::WindowSystemMenuHint);"
in cupcalibration.cpp and multipointcalibration.cpp.I am unsure how to proceed. Other posts suggest assessing issues with the parent and child relations between the objects but I was unable to understand any difference in flags used between the post and my code.
I have also tried to move the object around using this->move(200, 100);. It has worked, though doesn't directly help much. Please let me know if more information is required.
-
Hi,
What is your goal with opening a dialog in a widget constructor ?