2017-10-20 88 views
1

是否可以向父窗口動態添加新的子窗口小部件?動態添加疊加窗口小部件

我有以下代碼:

MyWidget : public QWidget 
{ 
    MyWidget() : Qwidget() 
    { 
     m_otherWidgets.push_back(new OtherWidget(this)); // this will be painted 
    } 

    void addNew() 
    { 
     m_otherWidgets.push_back(new OtherWidget(this)); // this will not be painted 
    } 

    std::vector<OtherWidget*> m_otherWidgets; 
} 

MyWidget bar(); // 1 other widget painted 
bar.addNew(); // still only 1 other widget painted 

矢量m_otherWidgets包含子控件的列表。問題是它只顯示在構造函數時間創建的子窗口小部件。

回答

2

沒有更多的信息,我只能猜測,但你可能忘了打電話給show()/setVisible(true)。在顯示父項後添加的小部件並不總是顯示。

+0

謝謝,這解決了這個問題。 – Serbin

相關問題