RECHERCHER :
COMMUNAUTE MP
Identifiez vous ...
Devenir Membre
J'ai oublié mon MDP
DOMAINE MP
Bavardages
Langages Généraux
Langages Web
Langages DotNet
Autres langages
Dev. Jeux Video
Sécurité
Sys. Exploitation
Graphismes
Logiciels
Réseaux
Bases de données
Méthodologies
Emplois High-tech
Aide juridique
Articles juridiques
FORUM
Index des forums
Ajouter un sujet
Rechercher sujet
Contact Responsable
Devenir modérateur
CHAT MP IRC
Votre pseudo ...
Srv: irc.moteurprog.com
Chan: #MoteurProg
PARTICIPER
Plus de 3500 emplois.
Rechercher un job
Déposez votre CV
Emplois High-tech

Visiteur MP

 Design Pattern

Forum : LIBRAIRIE C++ - GTK
Sous Catégorie : GTK
Type du sujet : Sujet Normale
FAQ : FAQ LIBRAIRIE C++ - GTK

SUIVI DES SUJETS PAR MAIL

SUIVI PAR MAIL INACTIF

RESOLUTION DU SUJET SUJET NON RESOLU
BLOQUAGE DU SUJET SUJET ACTIF
APPARTENANCE A LA FAQ N'APPARTIENT PAS A LA FAQ


POSTER UN NOUVEAU SUJET REPONDRE A CE SUJET

FORUM LIBRAIRIE C++ - GTK

PREMIERE PAGE

PAGE PRECEDENTE

Page précedente

Page suivante

PAGE SUIVANTE

DERNIERE PAGE
Raish
Membre du club
Avatar de Raish
Inscrit : 29/11/2004
Messages : 536
Message
#103857
Posté le 28/06/06 à 16:44
Bonjour à tous/toutes!

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:


//MYWIDGET_H: #ifndef MYWIDGET_H #define MYWIDGET_H #include "ClassUi.hpp" class MyWidget : public QWidget { Q_OBJECT public: MyWidget(QWidget *parent = 0); Ui_Form *EtatUi; private slots: void slotQuitter(); void slotChangeDesignPattern1(); void slotChangeDesignPattern2(); void slotInformation(); }; #endif //MYWIDGET_CPP: #include "MyWidget.hpp" MyWidget::MyWidget(QWidget *parent) : QWidget(parent) { EtatUi = new Ui_Etat1; EtatUi->setupUi(this); connect(EtatUi->pushButton, SIGNAL(clicked()), this, SLOT(slotInformation())); connect(EtatUi->pushButton_2, SIGNAL(clicked()), this, SLOT(slotChangeDesignPattern2())); connect(EtatUi->pushButton_3, SIGNAL(clicked()), qApp, SLOT(quit())); } void MyWidget::slotChangeDesignPattern1() { delete EtatUi; EtatUi = new Ui_Etat1; EtatUi->setupUi(this); connect(EtatUi->pushButton, SIGNAL(clicked()), this, SLOT(slotInformation())); connect(EtatUi->pushButton_2, SIGNAL(clicked()), this, SLOT(slotChangeDesignPattern2())); connect(EtatUi->pushButton_3, SIGNAL(clicked()), qApp, SLOT(quit())); } void MyWidget::slotChangeDesignPattern2() { delete EtatUi; EtatUi = new Ui_Etat2; EtatUi->setupUi(this); connect(EtatUi->pushButton_4, SIGNAL(clicked()), this, SLOT(slotChangeDesignPattern1())); connect(EtatUi->pushButton_5, SIGNAL(clicked()), qApp, SLOT(quit())); } void MyWidget::slotInformation() { QMessageBox mb("Informations","QMessage affichée. Contient les informations.", QMessageBox::Information, QMessageBox::Ok, QMessageBox::Default, QMessageBox::Default | QMessageBox::Default); mb.setButtonText(QMessageBox::Ok, "Fermer"); mb.exec(); } void MyWidget::slotQuitter() { qApp->quit(); }


Puis j'en demande l'éxecution et l'affichage (rien de spécial jusque là) :

//MAIN_CPP: #include "MyWidget.hpp" int main(int argc, char *argv[]) { QApplication app(argc, argv); MyWidget widget; widget.show(); return app.exec(); }


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 Smiley.

HAUT DE PAGE

PROFIL MEMBRE LUI ECRIRE 


    PAGE : [1]



.: Site Web développé par Julien Pichot et l'équipe MPWG avec www.evolvia-web.com :.