[英]QTabWidget not appearing
我在創建UI時遇到了一些困難。
我需要的 :
1個QTabWidget,其中3個QWidget作為選項卡。 這些小部件之一包含QPushButton,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派生的類,構造函數中只有setupUi。 我可以使用show()
查看我的QTabWidget,但無法將其放入頁面中。
謝謝
感謝thuga幫助我。
解決方案是將Layout放入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);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.