Adding a .ui file to TabWidget
-
Hey all,
My program I am working on has two .ui files. The first of these (browser.ui) creates a layout with a TabWidget and a button. When I click the button, it adds another tab to the TabWidget. I would like the new tab to be filled with my second ui file (TabContent.ui). How can I do this?
code:
browser.cpp:
@#include "browser.h"
#include "ui_browser.h"
#include "ui_TabContent.h"browser::browser(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::browser)
{
ui->setupUi(this);
}browser::~browser()
{
delete ui;
}void browser::on_NewTabButton_clicked()
{
!!NEEDS TO BE FILLED WITH TABCONTENT.UI!!}
@ -
If I understand what you said, do the following:
- Go to QTCreator
- In toolbar click in "File"
- See: File > New File or Project (or Ctrl+N)
- See: Chosse a template > Files and classes > C++ > C++ Class
- Now will open a window named "C++ Class Wizard".
- In "Class Name:" enter with text: "MyCustomWidget"
- In "Base class:" enter with text: "QTabWidget" (or outher widget type)
- Click in "Next" > click in "Finish".
- 3 files were created: mycustomwidget.h, mycustomwidget.cpp, mycustomwidget.cpp (you must have all 3 files so you can work with other classes)
your browser.cpp should look like:
@#include "browser.h"
#include "ui_browser.h"
#include "ui_TabContent.h"browser::browser(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::browser)
{
ui->setupUi(this);
}browser::~browser()
{
delete ui;
}void browser::on_NewTabButton_clicked()
{
MyCustomWidget *a = new MyCustomWidget(this);//or new MyCustomWidget;
ui->centralWidget->layout()->addWidget(a);
}@bq. Note: centralWidget is a standard widget in all projects created from scratch