PDA

View Full Version : Add custom widget to a mainwindow



aguleo
6th May 2013, 15:08
Supose i have a QWidget ...


#-------------------------------------------------
#
# Project created by QtCreator 2013-05-06T14:58:35
#
#-------------------------------------------------

QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = widget
TEMPLATE = app


SOURCES += main.cpp\
widget.cpp

HEADERS += widget.h

FORMS += widget.ui

... and a QMainWindow ...


#-------------------------------------------------
#
# Project created by QtCreator 2013-05-06T15:00:31
#
#-------------------------------------------------

QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = mainwindow
TEMPLATE = app


SOURCES += main.cpp\
mainwindow.cpp

HEADERS += mainwindow.h

FORMS += mainwindow.ui

Both were created separately.

Now i want to use the Widget as the centralWidget of the mainwindow.
If i copy the widget folder to the mainwindow folder, what is the next step to integrate them?

Lesiok
6th May 2013, 15:12
No, You have two project files. Why ? Just create one project file integrating all cpp, h and ui files.The rest is a simple C++.

aguleo
6th May 2013, 15:14
I was thinking of renaming the .pro to .pri, in the widget, and then make the necessary changings.
After that, i should try to promote the widget and set it a central widget.
The idea was to keep them separated as mush as possible!

Santosh Reddy
6th May 2013, 15:14
Now i want to use the Widget as the centralWidget of the mainwindow.
If i copy the widget folder to the mainwindow folder, what is the next step to integrate them?
Add the windget files to the mainwindow project

aguleo
7th May 2013, 14:49
Add the windget files to the mainwindow project
But this can be done via a pri file...right?

Added after 1 4 minutes:

It works by doing:
1 - placing the widget folder inside the mainwindows folder;
2 - adding include(widget/widget.pri) to mainwindow.pro
3 - renamming the widget.pro to widget.pri and changing it's content to:


SOURCES += widget/widget.cpp

HEADERS += widget/widget.h

FORMS += widget/widget.ui


It gives me a good organization in QtCreator but, after making all this changes, it might be better to simply add everything to the mainwindow.pro :)