是否可以动态添加新的子部件到父部件?
我有以下代码:
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
Vector m_otherWidgets
包含一个子控件列表。问题是它只显示在构造函数期间创建的这个子部件。
最佳答案
没有更多信息我只能猜测,但您可能忘记调用 show()
/setVisible(true)
。在父级显示后添加的小部件并不总是显示。
关于c++ - 动态添加覆盖小部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46846159/