5

我有一个海军陆战队项目,我有以下文件结构。

海军陆战队专业版

形式

伊朗海军陆战队.h

标头

伊朗海军陆战队.h

来源

伊朗.cpp main.cpp 海军陆战队.cpp

我在海军陆战队项目中添加了伊朗小部件。

这是marines.cpp

#include <QtGui>
#include "marines.h"
#include "iran.h"


marines::marines(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::marines)
{
    ui->setupUi(this);
    connect(ui->actionExit, SIGNAL(triggered()), this, SLOT(close()));
    connect(ui->actionIran, SIGNAL(triggered()), this, SLOT(ir()));
}

void marines::ir()
{
//slot to display iran ui inside my main window
}

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

这是我的 iran.cpp

#include "iran.h"
#include <QtGui>

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

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

如何显示我在 qt 设计器中制作的小部件伊朗?

4

2 回答 2

12

这完全取决于您希望小部件如何显示。

  1. 您可以在 MainWindow 中向中央小部件添加布局,并将自定义小部件添加到布局中
  2. 如果您希望自定义小部件成为 MainWindow 的 centralWidget,请使用 setCentralWidget
  3. 如果您希望自定义小部件作为子窗口,则将 MdiArea 添加到您的 MainWindow。然后将自定义小部件添加到您的 MdiArea。
  4. If you just want the custom widget to be displayed as a window then just "widget.show()"

Its better to look at Qt's examples to understand how a MainWindow is used.

于 2011-09-18T19:25:23.653 回答
3
marines::marines(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::marines)
{
    ui->setupUi(this); // after this
    iran *ir = new iran(); // create variable ir
    ir->show(); // show window
    ...
}
于 2011-09-18T22:28:39.683 回答