J'aimerai appliquer le design pattern à une application Qt, me permettant après un clique sur un bouton spécifique, de changer l'intérieur de la fenêtre pour un tout autre aspect avec d'autres Widgets.
Pour cela, j'ai issue une classe personnelle MyWidget de QWidget:
Puis j'ai "codé" (avec uic en console) une classe issue de deux design que j'ai déclinée grace au polymorphisme (afin de choisir quel design insérer dans ma fenêtre).
Dans MyWidget le design est contenu par "Ui_Form *EtatUi;":
//CLASSUI_HPP:
#ifndef CLASSUI_H
#define CLASSUI_H
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QPushButton>
#include <QtGui/QWidget>
#include <QtGui/QMessageBox>
#include <QtGui/QLineEdit>
#include <QtGui/QTextEdit>
class Ui_Form
{
public:
QPushButton *pushButton;
QPushButton *pushButton_2;
QPushButton *pushButton_3;
QLineEdit *lineEdit;
QLineEdit *lineEdit_2;
QLineEdit *lineEdit_3;
// /*-/*-/*-/*-/*-/*-/-*/-*/-*/*-/*-/-*/
QTextEdit *textEdit;
QPushButton *pushButton_4;
QPushButton *pushButton_5;
QLineEdit *lineEdit_4;
Ui_Form() {}
virtual ~Ui_Form()
{
delete pushButton;
delete pushButton_2;
delete pushButton_3;
delete lineEdit;
delete lineEdit_2;
delete lineEdit_3;
delete pushButton_4;
delete pushButton_5;
delete textEdit;
delete lineEdit_4;
}
virtual void setupUi(QWidget *Form) = 0;
virtual void retranslateUi(QWidget *Form) = 0;
};
class Ui_Etat1 : public Ui_Form
{
public:
Ui_Etat1() {
}
void setupUi(QWidget *Form)
{
Form->setObjectName(QString::fromUtf8("Form"));
Form->resize(QSize(516, 165).expandedTo(Form->minimumSizeHint()));
pushButton_2 = new QPushButton(Form);
pushButton_2->setObjectName(QString::fromUtf8("pushButton_2"));
pushButton_2->setGeometry(QRect(10, 20, 131, 71));
lineEdit = new QLineEdit(Form);
lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
lineEdit->setGeometry(QRect(10, 110, 501, 31));
lineEdit_3 = new QLineEdit(Form);
lineEdit_3->setObjectName(QString::fromUtf8("lineEdit_3"));
lineEdit_3->setGeometry(QRect(162, 70, 221, 20));
lineEdit_2 = new QLineEdit(Form);
lineEdit_2->setObjectName(QString::fromUtf8("lineEdit_2"));
lineEdit_2->setGeometry(QRect(310, 30, 191, 20));
pushButton = new QPushButton(Form);
pushButton->setObjectName(QString::fromUtf8("pushButton"));
pushButton->setGeometry(QRect(180, 20, 81, 31));
pushButton_3 = new QPushButton(Form);
pushButton_3->setObjectName(QString::fromUtf8("pushButton_3"));
pushButton_3->setGeometry(QRect(410, 60, 81, 31));
retranslateUi(Form);
QMetaObject::connectSlotsByName(Form);
} // setupUi
void retranslateUi(QWidget *Form)
{
Form->setWindowTitle(QApplication::translate("Form", "Design 1", 0, QApplication::UnicodeUTF8));
pushButton_2->setText(QApplication::translate("Form", "Change To Form2", 0, QApplication::UnicodeUTF8));
lineEdit->setText(QApplication::translate("Form", "You are here in the Form1 Design, to change of Design, click on PushButton named \"Change To Form2\"", 0, QApplication::UnicodeUTF8));
lineEdit_3->setText(QApplication::translate("Form", "If you want to quit, click on this PushButton", 0, QApplication::UnicodeUTF8));
lineEdit_2->setText(QApplication::translate("Form", "This PushButton open a QMessageBox", 0, QApplication::UnicodeUTF8));
pushButton->setText(QApplication::translate("Form", "Information", 0, QApplication::UnicodeUTF8));
pushButton_3->setText(QApplication::translate("Form", "QUITTER", 0, QApplication::UnicodeUTF8));
Q_UNUSED(Form);
} // retranslateUi
};
class Ui_Etat2 : public Ui_Form
{
public:
Ui_Etat2() {}
void setupUi(QWidget *Form)
{
Form->setObjectName(QString::fromUtf8("Form"));
Form->resize(QSize(338, 148).expandedTo(Form->minimumSizeHint()));
pushButton_4 = new QPushButton(Form);
pushButton_4->setObjectName(QString::fromUtf8("pushButton_4"));
pushButton_4->setGeometry(QRect(10, 20, 131, 71));
textEdit = new QTextEdit(Form);
textEdit->setObjectName(QString::fromUtf8("textEdit"));
textEdit->setGeometry(QRect(150, 13, 181, 81));
pushButton_5 = new QPushButton(Form);
pushButton_5->setObjectName(QString::fromUtf8("pushButton_5"));
pushButton_5->setGeometry(QRect(250, 110, 81, 31));
lineEdit_4 = new QLineEdit(Form);
lineEdit_4->setObjectName(QString::fromUtf8("lineEdit_4"));
lineEdit_4->setGeometry(QRect(10, 120, 221, 20));
retranslateUi(Form);
QMetaObject::connectSlotsByName(Form);
} // setupUi
void retranslateUi(QWidget *Form)
{
Form->setWindowTitle(QApplication::translate("Form", "Design 2", 0, QApplication::UnicodeUTF8));
pushButton_4->setText(QApplication::translate("Form", "Change To Form1", 0, QApplication::UnicodeUTF8));
textEdit->setHtml(QApplication::translate("Form", "<html><head><meta name=\"qrichtext\" content=\"1\" /></head><body style=\" white-space: pre-wrap; font-family:MS Shell Dlg 2; font-size:8.25pt; font-weight:400; font-style:normal; text-decoration:none;\"><p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;\">You are here in the Form2 Design, to change of Design, click on PushButton named \"Change To Form1\"</p></body></html>", 0, QApplication::UnicodeUTF8));
pushButton_5->setText(QApplication::translate("Form", "QUITTER", 0, QApplication::UnicodeUTF8));
lineEdit_4->setText(QApplication::translate("Form", "If you want to quit, click on this PushButton", 0, QApplication::UnicodeUTF8));
Q_UNUSED(Form);
} // retranslateUi
};
#endif //CLASSUI_H
Ainsi tout marche parfaitement en ce qui concerne le dessinage du design et sa supression mais pas la reconstruction du second design.
Pourriez-vous m'aider?
A l'aide de QMessageBox j'ai vu que l'éxecution de toutes les méthodes se faisait bien, ainsi que la redimension de la fenêtre.
PS: je vous évite le fichier mocMyWidget.cpp issu de MyWidget.hpp par l'utilitaire moc .