PHP#include "fuzzygui.h"#include "ui_fuzzygui.h" #include <QMessageBox>#include <QSpacerItem>#include <QGridLayout> FuzzyGUI::FuzzyGUI(QWidget *parent) : QMainWindow(parent), ui(new Ui::FuzzyGUI){ ui->setupUi(this);} FuzzyGUI::~FuzzyGUI(){ delete ui;} void FuzzyGUI::on_actionExit_triggered(){ qApp->quit();} void FuzzyGUI::on_actionUpdates_triggered(){ QMessageBox updateOptions; updateOptions.setWindowTitle(tr("Update Checker")); updateOptions.setIcon(QMessageBox::Question); updateOptions.setText(tr("Are you sure there will be any updates?")); updateOptions.setStandardButtons(QMessageBox::Yes | QMessageBox::No); updateOptions.setDefaultButton(QMessageBox::No); // Workaround for setting QMessageBox size // QSpacerItem* horizontalSpacer = new QSpacerItem(300, 100, QSizePolicy::Fixed, QSizePolicy::Fixed); QGridLayout* layout = (QGridLayout*)updateOptions.layout(); layout->addItem(horizontalSpacer, 0, 0, 0, 0); int userChoice = updateOptions.exec(); QMessageBox choiceConfirmation; choiceConfirmation.setWindowTitle(tr("Update Checker")); choiceConfirmation.setIcon(QMessageBox::Information); choiceConfirmation.setStandardButtons(QMessageBox::Ok); if (userChoice == QMessageBox::Yes) { choiceConfirmation.setText(tr("Wrong guess")); } else { choiceConfirmation.setText(tr("That is correct")); } // Workaround for setting QMessageBox size // layout = (QGridLayout*)choiceConfirmation.layout(); layout->addItem(horizontalSpacer, 0, 0, 0, 0); choiceConfirmation.exec();}
PHP#ifndef FUZZYGUI_H#define FUZZYGUI_H #include <QMainWindow> namespace Ui {class FuzzyGUI;} class FuzzyGUI : public QMainWindow{ Q_OBJECT public: explicit FuzzyGUI(QWidget *parent = 0); ~FuzzyGUI(); private slots: void on_actionExit_triggered(); void on_actionUpdates_triggered(); private: Ui::FuzzyGUI *ui;}; #endif // FUZZYGUI_H
PHP#include "fuzzygui.h"#include <QApplication> int main(int argc, char *argv[]){ QApplication a(argc, argv); FuzzyGUI w; w.show(); return a.exec();}
layout = (QGridLayout*)ch
PHP#include "fuzzygui.h"#include "ui_fuzzygui.h" #include <QGridLayout>#include <QMessageBox>#include <QPixmap>#include <QSpacerItem> FuzzyGUI::FuzzyGUI(QWidget *parent) : QMainWindow(parent), ui(new Ui::FuzzyGUI){ ui->setupUi(this);} FuzzyGUI::~FuzzyGUI(){ delete ui;} void FuzzyGUI::on_actionExit_triggered(){ qApp->quit();} void FuzzyGUI::on_actionUpdates_triggered(){ QMessageBox updateOptions; updateOptions.setWindowTitle(tr("Update Checker")); updateOptions.setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint); updateOptions.setIcon(QMessageBox::Question); updateOptions.setText(tr("Are you sure there will be any updates?")); updateOptions.setStandardButtons(QMessageBox::Yes | QMessageBox::No); updateOptions.setDefaultButton(QMessageBox::No); // Workaround for setting QMessageBox size // QSpacerItem* horizontalSpacer = new QSpacerItem(300, 100, QSizePolicy::Fixed, QSizePolicy::Fixed); dynamic_cast<QGridLayout*>(updateOptions.layout())->addItem(horizontalSpacer, 0, 0, 0, 0); int userChoice = updateOptions.exec(); QPixmap invisibleIcon = QPixmap(1, 1); QMessageBox choiceConfirmation; choiceConfirmation.setWindowTitle(tr("Update Checker")); choiceConfirmation.setWindowIcon(QIcon(invisibleIcon)); choiceConfirmation.setIcon(QMessageBox::Information); choiceConfirmation.setStandardButtons(QMessageBox::Ok); if (userChoice == QMessageBox::Yes) { choiceConfirmation.setText(tr("Wrong guess")); } else { choiceConfirmation.setText(tr("That is correct")); } // Workaround for setting QMessageBox size // horizontalSpacer = new QSpacerItem(300, 100, QSizePolicy::Fixed, QSizePolicy::Fixed); dynamic_cast<QGridLayout*>(choiceConfirmation.layout())->addItem(horizontalSpacer, 0, 0, 0, 0); choiceConfirmation.exec();}
C++ (Qt)void QWidgetPrivate::adjustFlags(Qt::WindowFlags &flags, QWidget *w){... if (flags & Qt::CustomizeWindowHint) { // modify window flags to make them consistent. // Only enable this on non-Mac platforms. Since the old way of doing this would // interpret WindowSystemMenuHint as a close button and we can't change that behavior // we can't just add this in.#ifndef Q_WS_MAC if (flags & (Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint | Qt::WindowContextHelpButtonHint)) { flags |= Qt::WindowSystemMenuHint;#else if (flags & (Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint | Qt::WindowSystemMenuHint)) {#endif flags |= Qt::WindowTitleHint; flags &= ~Qt::FramelessWindowHint; } } else if (customize && !(flags & Qt::FramelessWindowHint)) { // if any of the window hints that affect the titlebar are set // and the window is supposed to have frame, we add a titlebar // and system menu by default. flags |= Qt::WindowSystemMenuHint; flags |= Qt::WindowTitleHint; }}