QTabWidget not appearing



我很难创建我的UI。

我需要的:

1 QTABWIDGET,带有3个Qwidget作为选项卡。这些小部件之一包含qpushbuttons,qlineedits,必须包含另一个qtabwidget。

我的问题:

我在其他qtabwidget上取得了成功,这不是出现的。我已经手动将qpushbutton和Qlineedit放在.UI文件中。现在,我想在同一页面上动态创建QTABWIDGET。

我的页面代码:

namespace Ui
{
class cImageInterface;
} 
class cImageInterface : public QWidget
{
    Q_OBJECT
public:
    cImageInterface();
    ~cImageInterface();
private:
    Ui::cImageInterface* ui;
cAppTabWidget* tabW_Application;
};

构造函数:

cImageInterface::cImageInterface() : ui(new Ui::cImageInterface)
{
  tabW_Application = new cAppTabWidget(this);
  ui->setupUi(this);
}

qtabwidget代码:

class cAppTabWidget : public QTabWidget
{
    Q_OBJECT
public:
    explicit cAppTabWidget(QWidget* parent);
    ~cAppTabWidget();
protected:
private:
Ui::cAppTabWidget* ui;
cAppInterface* tab_Application;
int m_NbTab;
};

概要:

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只是一个Qwidget派生类,在构造函数中只有一个设置。我可以使用show()看到我的QTABWIDGET,但我无法将其放入我的页面中。

谢谢

感谢Thuga帮助我。

解决方案是将布局放入cImageInterface,然后将QTabWidget放入其中。

我通过在我的代码中创建它来遇到问题,因此我将其放在.UI文件中。

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

然后您可以:

cImageInterface::cImageInterface() : ui(new Ui::cImageInterface)
{
  tabW_Application = new cAppTabWidget(this);
  ui->setupUi(this);
  ui->appTabLayout->addWidget(tabW_Application);
}

最新更新