简体   繁体   English

QTabWidget没有出现

[英]QTabWidget not appearing

I have some difficulties to create my UI. 我在创建UI时遇到了一些困难。

What I need : 我需要的 :

1 QTabWidget with 3 QWidget as tabs. 1个QTabWidget,其中3个QWidget作为选项卡。 One of these Widget contains QPushButtons, QLineEdits, and have to contain another QTabWidget. 这些小部件之一包含QPushButton,QLineEdits,并且还必须包含另一个QTabWidget。

My problem : 我的问题 :

Where I've sucess on my other QTabWidget, this one is not appearing. 在其他QTabWidget上成功运行的地方,这个没有出现。 I've manually put QPushButton and QLineEdit in the .ui file. 我已经手动将QPushButton和QLineEdit放在.ui文件中。 Now I want to dynamically create a QTabWidget on this same page. 现在,我想在同一页面上动态创建QTabWidget。

My page code : 我的页面代码:

namespace Ui
{
class cImageInterface;
} 

class cImageInterface : public QWidget
{
    Q_OBJECT

public:
    cImageInterface();
    ~cImageInterface();

private:
    Ui::cImageInterface* ui;

cAppTabWidget* tabW_Application;
};

Constructor : 构造函数:

cImageInterface::cImageInterface() : ui(new Ui::cImageInterface)
{
  tabW_Application = new cAppTabWidget(this);

  ui->setupUi(this);
}

QTabWidget code : QTabWidget代码:

class cAppTabWidget : public QTabWidget
{
    Q_OBJECT

public:
    explicit cAppTabWidget(QWidget* parent);
    ~cAppTabWidget();

protected:

private:
Ui::cAppTabWidget* ui;
cAppInterface* tab_Application;
int m_NbTab;
};

Contructor : 建设者:

cAppTabWidget::cAppTabWidget(QWidget* parent)
                            : ui(new Ui::cAppTabWidget)
                            , tab_Application(new cAppInterface)
                            , m_NbTab(1)
{
  this->setGeometry(0, 230, 800, 360);
  this->addTab(tab_Application, "App5896");
}

cAppInterface is just a QWidget derived class, with only a setupUi in the constructor. cAppInterface只是QWidget派生的类,构造函数中只有setupUi。 I'm able to see my QTabWidget with show() but I'm not able to put it inside my page. 我可以使用show()查看我的QTabWidget,但无法将其放入页面中。

Thanks 谢谢

Thanks to thuga for helping me. 感谢thuga帮助我。

The solution was to put a Layout into cImageInterface and then put the QTabWidget in it. 解决方案是将Layout放入cImageInterface ,然后将QTabWidget放入其中。

I've faced a problem by tring to create it in my code, so I've put it in the .ui file. 我在尝试在代码中创建它时遇到了一个问题,因此将其放在.ui文件中。

<layout class="QVBoxLayout" name="appTabLayout">
<property name="sizeConstraint">
 <enum>QLayout::SetNoConstraint</enum>
</property>

and then you can : 然后您可以:

cImageInterface::cImageInterface() : ui(new Ui::cImageInterface)
{
  tabW_Application = new cAppTabWidget(this);

  ui->setupUi(this);

  ui->appTabLayout->addWidget(tabW_Application);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM