Qt两个不同的设计形式类

时间:2021-03-19 12:08:09

I have two design form class , i want to insert into tabWidget (at pharmacymainwindow.ui ) the test2_tab_1 ( which is at test2.ui) ?

我有两个设计表单类,我想插入tabWidget(在pharmacymainwindow.ui)test2_tab_1(在test2.ui)?

Any idea, how can i use ui object of a class at another ui ? the ui of one design form class is private i have no idea how can i access it from another designer form class.

任何想法,我如何在另一个ui使用ui的对象?一个设计表单类的ui是私有的我不知道如何从另一个设计器表单类访问它。

pharmacymainwindow.h

#ifndef PHARMACYMAINWINDOW_H
#define PHARMACYMAINWINDOW_H

#include <QMainWindow>
#include <QDebug>
#include "test2.h"

namespace Ui {
class PharmacyMainWindow;
}

class MainWindow;
class PharmacyMainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit PharmacyMainWindow(QWidget *parent = 0);
    ~PharmacyMainWindow();

private slots:
    void on_tabWidget_tabCloseRequested(int index);

    void on_pushButton_clicked();

private:
    Ui::PharmacyMainWindow *ui;
};

#endif // PHARMACYMAINWINDOW_H

pharmacymainwindow.cpp

#include "pharmacymainwindow.h"
#include "ui_pharmacymainwindow.h"

PharmacyMainWindow::PharmacyMainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::PharmacyMainWindow)
{
    ui->setupUi(this);
    ui->tabWidget->setTabsClosable(true);
}

PharmacyMainWindow::~PharmacyMainWindow()
{
    delete ui;
}

void PharmacyMainWindow::on_tabWidget_tabCloseRequested(int index)
{
    if(index != 0)
    ui->tabWidget->removeTab(index);

}

void PharmacyMainWindow::on_pushButton_clicked()
{    

    //ui->tabWidget->insertTab(????????????????);
    //ui->tabWidget->setCurrentIndex(?);

}

test2.h

#ifndef TEST2_H
#define TEST2_H

#include <QMainWindow>
namespace Ui {
class test2;
}

class test2 : public QMainWindow
{
    Q_OBJECT

public:
    explicit test2(QWidget *parent = 0);
    ~test2();

private:
    Ui::test2 *ui;

};

#endif // TEST2_H

test2.cpp

#include "test2.h"
#include "ui_test2.h"

test2::test2(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::test2)
{
    ui->setupUi(this);
}

test2::~test2()
{
    delete ui;
}

1 个解决方案

#1


0  

Ui::test2 *ui is a member-class responsible for filling a widget: ui->setupUi(this), it is not a widget, so you should not use it to insert it in a tab, what you should do is create a widget and insert it:

Ui :: test2 * ui是一个负责填充小部件的成员类:ui-> setupUi(this),它不是一个小部件,所以你不应该用它来将它插入一个标签,你应该做的就是创建一个小部件并插入它:

void PharmacyMainWindow::on_pushButton_clicked()
{
    ui->tabWidget->insertTab(0, new test2,"new tab");
}

#1


0  

Ui::test2 *ui is a member-class responsible for filling a widget: ui->setupUi(this), it is not a widget, so you should not use it to insert it in a tab, what you should do is create a widget and insert it:

Ui :: test2 * ui是一个负责填充小部件的成员类:ui-> setupUi(this),它不是一个小部件,所以你不应该用它来将它插入一个标签,你应该做的就是创建一个小部件并插入它:

void PharmacyMainWindow::on_pushButton_clicked()
{
    ui->tabWidget->insertTab(0, new test2,"new tab");
}