Originally Posted by
Santosh Reddy
That can be done using QWizard, the push button can be linked to any wizard page.
Load mainwindow.ui into widget, load mainwindow1.ui into widget1 and then put widget and widget1 into QStackedWidget
I have attached my project files, can you please help with loding ui files. I am not so trong in C++, i am studing for it.
I am using Qt Creator 2.4.1
Based on Qt 4.8.0 (32 bit)
Built on Mar 21 2012
main.cpp
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
MainWindow w;
w.show();
return a.exec();
}
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
// Load Screen 2
}
void MainWindow::on_pushButton_2_clicked()
{
// Load Screen 3
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
// Load Screen 2
}
void MainWindow::on_pushButton_2_clicked()
{
// Load Screen 3
}
To copy to clipboard, switch view to plain text mode
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
private slots:
void on_pushButton_clicked();
void on_pushButton_2_clicked();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_pushButton_clicked();
void on_pushButton_2_clicked();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
mainwindow.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralWidget">
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>50</x>
<y>170</y>
<width>131</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>Go To Screen 2</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_2">
<property name="geometry">
<rect>
<x>237</x>
<y>170</y>
<width>121</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>Go To Screen 3</string>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>150</x>
<y>60</y>
<width>81</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>Screen 1</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>25</height>
</rect>
</property>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<widget class="QStatusBar" name="statusBar"/>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralWidget">
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>50</x>
<y>170</y>
<width>131</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>Go To Screen 2</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_2">
<property name="geometry">
<rect>
<x>237</x>
<y>170</y>
<width>121</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>Go To Screen 3</string>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>150</x>
<y>60</y>
<width>81</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>Screen 1</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>25</height>
</rect>
</property>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<widget class="QStatusBar" name="statusBar"/>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>
To copy to clipboard, switch view to plain text mode
Now using Add New... -> Qt Designer Form Class -> Main Window i have created 2 UI
mainwindow1.cpp
#include "mainwindow1.h"
#include "ui_mainwindow1.h"
MainWindow1
::MainWindow1(QWidget *parent
) : ui(new Ui::MainWindow1)
{
ui->setupUi(this);
}
MainWindow1::~MainWindow1()
{
delete ui;
}
void MainWindow1::on_pushButton_clicked()
{
// Load Screen 1
}
void MainWindow1::on_pushButton_2_clicked()
{
// Load Screen 3
}
#include "mainwindow1.h"
#include "ui_mainwindow1.h"
MainWindow1::MainWindow1(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow1)
{
ui->setupUi(this);
}
MainWindow1::~MainWindow1()
{
delete ui;
}
void MainWindow1::on_pushButton_clicked()
{
// Load Screen 1
}
void MainWindow1::on_pushButton_2_clicked()
{
// Load Screen 3
}
To copy to clipboard, switch view to plain text mode
mainwindow1.h
#ifndef MAINWINDOW1_H
#define MAINWINDOW1_H
#include <QMainWindow>
namespace Ui {
class MainWindow1;
}
{
Q_OBJECT
public:
explicit MainWindow1
(QWidget *parent
= 0);
~MainWindow1();
private slots:
void on_pushButton_clicked();
void on_pushButton_2_clicked();
private:
Ui::MainWindow1 *ui;
};
#endif // MAINWINDOW1_H
#ifndef MAINWINDOW1_H
#define MAINWINDOW1_H
#include <QMainWindow>
namespace Ui {
class MainWindow1;
}
class MainWindow1 : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow1(QWidget *parent = 0);
~MainWindow1();
private slots:
void on_pushButton_clicked();
void on_pushButton_2_clicked();
private:
Ui::MainWindow1 *ui;
};
#endif // MAINWINDOW1_H
To copy to clipboard, switch view to plain text mode
mainwindow1.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow1</class>
<widget class="QMainWindow" name="MainWindow1">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>57</x>
<y>150</y>
<width>111</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>Go To Screen 1</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_2">
<property name="geometry">
<rect>
<x>230</x>
<y>150</y>
<width>121</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>Go To Screen 3</string>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>150</x>
<y>50</y>
<width>66</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>Screen 2</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>25</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow1</class>
<widget class="QMainWindow" name="MainWindow1">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>57</x>
<y>150</y>
<width>111</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>Go To Screen 1</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_2">
<property name="geometry">
<rect>
<x>230</x>
<y>150</y>
<width>121</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>Go To Screen 3</string>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>150</x>
<y>50</y>
<width>66</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>Screen 2</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>25</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
To copy to clipboard, switch view to plain text mode
mainwindow2.cpp
#include "mainwindow2.h"
#include "ui_mainwindow2.h"
MainWindow2
::MainWindow2(QWidget *parent
) : ui(new Ui::MainWindow2)
{
ui->setupUi(this);
}
MainWindow2::~MainWindow2()
{
delete ui;
}
void MainWindow2::on_pushButton_clicked()
{
// Load Screen 1
}
void MainWindow2::on_pushButton_2_clicked()
{
// Load Screen 2
}
#include "mainwindow2.h"
#include "ui_mainwindow2.h"
MainWindow2::MainWindow2(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow2)
{
ui->setupUi(this);
}
MainWindow2::~MainWindow2()
{
delete ui;
}
void MainWindow2::on_pushButton_clicked()
{
// Load Screen 1
}
void MainWindow2::on_pushButton_2_clicked()
{
// Load Screen 2
}
To copy to clipboard, switch view to plain text mode
mainwindow2.h
#ifndef MAINWINDOW2_H
#define MAINWINDOW2_H
#include <QMainWindow>
namespace Ui {
class MainWindow2;
}
{
Q_OBJECT
public:
explicit MainWindow2
(QWidget *parent
= 0);
~MainWindow2();
private slots:
void on_pushButton_clicked();
void on_pushButton_2_clicked();
private:
Ui::MainWindow2 *ui;
};
#endif // MAINWINDOW2_H
#ifndef MAINWINDOW2_H
#define MAINWINDOW2_H
#include <QMainWindow>
namespace Ui {
class MainWindow2;
}
class MainWindow2 : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow2(QWidget *parent = 0);
~MainWindow2();
private slots:
void on_pushButton_clicked();
void on_pushButton_2_clicked();
private:
Ui::MainWindow2 *ui;
};
#endif // MAINWINDOW2_H
To copy to clipboard, switch view to plain text mode
mainwindow2.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow2</class>
<widget class="QMainWindow" name="MainWindow2">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>40</x>
<y>160</y>
<width>121</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>Go To Screen 1</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_2">
<property name="geometry">
<rect>
<x>217</x>
<y>160</y>
<width>121</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>Go To Screen 2</string>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>150</x>
<y>50</y>
<width>66</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>Screen 3</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>25</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow2</class>
<widget class="QMainWindow" name="MainWindow2">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>40</x>
<y>160</y>
<width>121</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>Go To Screen 1</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_2">
<property name="geometry">
<rect>
<x>217</x>
<y>160</y>
<width>121</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>Go To Screen 2</string>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>150</x>
<y>50</y>
<width>66</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>Screen 3</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>25</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
To copy to clipboard, switch view to plain text mode
MultiScr9.pro
#-------------------------------------------------
#
# Project created by QtCreator 2013-08-31T03:15:06
#
#-------------------------------------------------
QT += core gui
TARGET = MultiScr9
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
mainwindow1.cpp \
mainwindow2.cpp
HEADERS += mainwindow.h \
mainwindow1.h \
mainwindow2.h
FORMS += mainwindow.ui \
mainwindow1.ui \
mainwindow2.ui
#-------------------------------------------------
#
# Project created by QtCreator 2013-08-31T03:15:06
#
#-------------------------------------------------
QT += core gui
TARGET = MultiScr9
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
mainwindow1.cpp \
mainwindow2.cpp
HEADERS += mainwindow.h \
mainwindow1.h \
mainwindow2.h
FORMS += mainwindow.ui \
mainwindow1.ui \
mainwindow2.ui
To copy to clipboard, switch view to plain text mode
Added after 8 minutes:
Please find the project attached
-
Sahil Kulkarni
Bookmarks