Help with multiple forms...!
Hello all, I am completely new to this forum and quite new to QtCeator... I would like to ask some things about having multiple forms. Ok, let's say that we have a very simple program with only a button "Preferences". When you click this button a new Window (and not QMessageBox) is created with his own features etc... I know how to pop-up a MessageBox, but how do I open a whole new Window? The problem seems huge considering that you have to design its own ui and define its own settings.. Can anyone help me on this?
I give you the files:
mainwindow.h
Code:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
Q_OBJECT
public:
~MainWindow();
protected:
private:
Ui::MainWindow *ui;
private slots:
void on_pushButton_clicked();
};
#endif // MAINWINDOW_H
mainwindow.cpp
Code:
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow
::changeEvent(QEvent *e
) {
switch (e->type()) {
ui->retranslateUi(this);
break;
default:
break;
}
}
void MainWindow::on_pushButton_clicked()
{
//Here the other window should open up
}
main.cpp
Code:
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
MainWindow w;
w.show();
return a.exec();
}
Screenshot of Gui:
http://i30.tinypic.com/2v2tjia.png
I have to say that I had the idea an other executable to run each time you press the button preferences but this is quite noob I think :p:p:p
Re: Help with multiple forms...!
Hi,
please also note our Newbie section. I would suggest you to read the documentation about signal and slot mechanism and have a look at QDialog.
Lykurg
Re: Help with multiple forms...!
Thank you very much for the answer:)
Re: Help with multiple forms...!
Ok, let's see....
Code:
void MainWindow::on_pushButton_clicked()
{
dial->setWindowTitle("Hello world");
dial->show();
}
How can I edit this QDialog? Add buttons, labels, etc..?
Re: Help with multiple forms...!
Quote:
Originally Posted by
hakermania
How can I edit this QDialog? Add buttons, labels, etc..?
Like you do with any other QMainWindow or QWidget (which is the base for all other widgets.). And be aware that you delete the pointer somewhere.
Re: Help with multiple forms...!
You add just like in any other QWidgets
And don't forget to pas the MainWindow as a parent for your QDialog:
Code:
void MainWindow::on_pushButton_clicked()
{
dial->setWindowTitle("Hello world");
dial->show();
}
Re: Help with multiple forms...!
Re: Help with multiple forms...!
""You add just like in any other QWidgets""
And how do I exactly add these in "any other Widgets"???:confused::confused::confused:
Re: Help with multiple forms...!
please read the documentation or any book about Qt! Start the documentation on how to use layouts!