1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
#include<QtGui>
#include"MaFenetre.h"
MaFenetre::MaFenetre(QWidget *parent):QDialog(parent)
{
label = new QLabel("&Votre nom please");
line = new QLineEdit;
label->setBuddy(line);
okbutton = new QPushButton("&Ok");
cancelbutton = new QPushButton("&Cancel");
QHBoxLayout *horilayout_haut = new QHBoxLayout;
horilayout_haut->addWidget(label);
horilayout_haut->addWidget(line);
QHBoxLayout *horilayout_bas = new QHBoxLayout;
horilayout_bas->addWidget(okbutton);
horilayout_bas->addWidget(cancelbutton);
QVBoxLayout *layout = new QVBoxLayout;
layout->addLayout(horilayout_haut);
layout->addLayout(horilayout_bas);
setLayout(layout);
/**ordre tabulation**/
setTabOrder(label,okbutton);
setTabOrder(okbutton,cancelbutton);
/**CoOonexion**/
QObject::connect(okbutton,SIGNAL(clicked()),this,SLOT(accept()));
QObject::connect(cancelbutton,SIGNAL(clicked()),this,SLOT(reject()));
}
Mainwindow::Mainwindow():QWidget()
{
quitterbutton = new QPushButton("&Quitter");
aproposbutton = new QPushButton("&Apropos");
avoirnom = new QPushButton("&Donne le nom");
main_line = new QLineEdit;
QHBoxLayout *hori_layout = new QHBoxLayout;
hori_layout->addWidget(avoirnom);
hori_layout->addWidget(main_line);
QVBoxLayout *verti_layout = new QVBoxLayout;
verti_layout->addWidget(aproposbutton);
verti_layout->addWidget(quitterbutton);
QVBoxLayout *mainlayout = new QVBoxLayout;
mainlayout->addLayout(hori_layout);
mainlayout->addLayout(verti_layout);
setLayout(mainlayout);
/**CoOonection**/
QObject::connect(aproposbutton,SIGNAL(clicked()),qApp,SLOT(aboutQt()));
QObject::connect(quitterbutton,SIGNAL(clicked()),qApp,SLOT(quit()));
QObject::connect(avoirnom,SIGNAL(clicked()),this,SLOT(ouvrire_dialog()));
}
void Mainwindow::ouvrire_dialog()
{ resultat = 0;
resultat = fenetre.exec(); /**le probleme se situe ici **/
QString nom = fenetre.getText();/*je ne sais pas comment gerer**/
if(resultat) { /*la reponse*/
main_line->setText( nom );
}
} |
Partager