gen_mass
18th July 2010, 09:59
Hi,
I have a mainwindow with a toolbar. When the user clicks to a tool named DialogBox, I want my QWidget ''dialogue'' to open, so that the user can fill the questions ask in it. So, I tried to link the click signal of that tool to a slot (open_dialog()) where the coding of QWidget 'dialogue'' is,including a dialogue.show().
But that doesn't work...how can I do this ?
mainwindow::mainwindow(QWidget*p)
{
QWidget *central= new QWidget(0);
........
...........
.........
central->setLayout(layout);
setCentralWidget(central);
// Tool bar creation
QToolBar *toolBarFichier = addToolBar("Fichier");
QAction *actionQuitter = toolBarFichier->addAction("&Quit");
toolBarFichier->addAction(actionQuitter);
actionQuitter->setShortcut(QKeySequence("Ctrl+Q"));
actionQuitter->setIcon(QIcon("quit.png"));
connect(actionQuitter, SIGNAL(triggered()), qApp, SLOT(quit()));
//Informations about patient
QAction *actionDialogue = toolBarFichier->addAction("&Dialog box");
toolBarFichier->addAction(actionDialogue);
actionDialogue->setShortcut(QKeySequence("Ctrl+Q"));
actionDialogue->setIcon(QIcon("file.png"));
QObject::connect(actionDialogue, SIGNAL(triggered()), qApp, SLOT(open_dialog()));
}
void mainwindow::open_dialog()
{
QWidget dialogue;
QPalette pal = dialogue.palette();
pal.setColor(dialogue.backgroundRole(),Qt::white);
dialogue.setPalette(pal);
QLabel *intro = new QLabel("Informations relatives à la patiente");
QFont *font1;
QLabel *nameLabel = new QLabel("Nom:");
QLineEdit *nameLineEdit = new QLineEdit;
QLabel *prenomLabel = new QLabel("Prénom:");
QLineEdit *prenomLineEdit = new QLineEdit;
QLabel *ageLabel = new QLabel("Âge:");
QLineEdit *ageLineEdit = new QLineEdit;
QLabel *poidsLabel = new QLabel("Poids (kg):");
QLineEdit *poidsLineEdit = new QLineEdit;
QLabel *nbr_accLabel = new QLabel("Nombre d'accouchements vécus :");
QLineEdit *nbr_accLineEdit = new QLineEdit;
QPushButton *bouton1 = new QPushButton("Enregistrer ");
QPushButton *bouton2 = new QPushButton("Terminer");
QGridLayout *layout = new QGridLayout;
layout->addWidget(intro,0, 0);
layout->addWidget(nameLabel, 2, 0);
layout->addWidget(nameLineEdit, 2, 2,1,3);
layout->addWidget(prenomLabel, 3, 0);
layout->addWidget(prenomLineEdit, 3,2, 1,3);
layout->addWidget(ageLabel, 4, 0);
layout->addWidget(ageLineEdit, 4, 2);
layout->addWidget(poidsLabel, 5, 0);
layout->addWidget(poidsLineEdit, 5, 2);
layout->addWidget(nbr_accLabel, 6, 0);
layout->addWidget(nbr_accLineEdit, 6, 2);
layout->addWidget(bouton1, 8, 3);
layout->addWidget(bouton2, 8, 4);
dialogue.setLayout(layout);
dialogue.show();
}
Thanks for your helps !
I have a mainwindow with a toolbar. When the user clicks to a tool named DialogBox, I want my QWidget ''dialogue'' to open, so that the user can fill the questions ask in it. So, I tried to link the click signal of that tool to a slot (open_dialog()) where the coding of QWidget 'dialogue'' is,including a dialogue.show().
But that doesn't work...how can I do this ?
mainwindow::mainwindow(QWidget*p)
{
QWidget *central= new QWidget(0);
........
...........
.........
central->setLayout(layout);
setCentralWidget(central);
// Tool bar creation
QToolBar *toolBarFichier = addToolBar("Fichier");
QAction *actionQuitter = toolBarFichier->addAction("&Quit");
toolBarFichier->addAction(actionQuitter);
actionQuitter->setShortcut(QKeySequence("Ctrl+Q"));
actionQuitter->setIcon(QIcon("quit.png"));
connect(actionQuitter, SIGNAL(triggered()), qApp, SLOT(quit()));
//Informations about patient
QAction *actionDialogue = toolBarFichier->addAction("&Dialog box");
toolBarFichier->addAction(actionDialogue);
actionDialogue->setShortcut(QKeySequence("Ctrl+Q"));
actionDialogue->setIcon(QIcon("file.png"));
QObject::connect(actionDialogue, SIGNAL(triggered()), qApp, SLOT(open_dialog()));
}
void mainwindow::open_dialog()
{
QWidget dialogue;
QPalette pal = dialogue.palette();
pal.setColor(dialogue.backgroundRole(),Qt::white);
dialogue.setPalette(pal);
QLabel *intro = new QLabel("Informations relatives à la patiente");
QFont *font1;
QLabel *nameLabel = new QLabel("Nom:");
QLineEdit *nameLineEdit = new QLineEdit;
QLabel *prenomLabel = new QLabel("Prénom:");
QLineEdit *prenomLineEdit = new QLineEdit;
QLabel *ageLabel = new QLabel("Âge:");
QLineEdit *ageLineEdit = new QLineEdit;
QLabel *poidsLabel = new QLabel("Poids (kg):");
QLineEdit *poidsLineEdit = new QLineEdit;
QLabel *nbr_accLabel = new QLabel("Nombre d'accouchements vécus :");
QLineEdit *nbr_accLineEdit = new QLineEdit;
QPushButton *bouton1 = new QPushButton("Enregistrer ");
QPushButton *bouton2 = new QPushButton("Terminer");
QGridLayout *layout = new QGridLayout;
layout->addWidget(intro,0, 0);
layout->addWidget(nameLabel, 2, 0);
layout->addWidget(nameLineEdit, 2, 2,1,3);
layout->addWidget(prenomLabel, 3, 0);
layout->addWidget(prenomLineEdit, 3,2, 1,3);
layout->addWidget(ageLabel, 4, 0);
layout->addWidget(ageLineEdit, 4, 2);
layout->addWidget(poidsLabel, 5, 0);
layout->addWidget(poidsLineEdit, 5, 2);
layout->addWidget(nbr_accLabel, 6, 0);
layout->addWidget(nbr_accLineEdit, 6, 2);
layout->addWidget(bouton1, 8, 3);
layout->addWidget(bouton2, 8, 4);
dialogue.setLayout(layout);
dialogue.show();
}
Thanks for your helps !