从 QDialog::layout 中删除子项
class MyDialog : public QDialog
{
public:
MyDialog(QListWidget * w)
: m_w(w)
{
m_layout = new QGridLayout(this);
m_layout.addWidget( w );
this->exec();
}
~MyDialog() {
m_layout->removeWidget( m_w );
}
private:
QGridLayout * m_layout;
QListWidget * m_w;
}
w 也是主窗口布局的子窗口。问题是当 MyDialog 的对象被销毁时,它也会销毁 w ,而它是在 MyDialog 的析构函数中删除的;
您有比克隆 QListWidget w 更好的解决方案吗?
class MyDialog : public QDialog
{
public:
MyDialog(QListWidget * w)
: m_w(w)
{
m_layout = new QGridLayout(this);
m_layout.addWidget( w );
this->exec();
}
~MyDialog() {
m_layout->removeWidget( m_w );
}
private:
QGridLayout * m_layout;
QListWidget * m_w;
}
w is also a child of the main's window layout. The problem is when an object of MyDialog is destroy, it destroy w too whereas it was remove in the MyDialog's destructor;
Have you got a better solution than clone the QListWidget w ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你可以像这样做smf:
但我认为如果你必须克隆QListView,你可以做smf wrog。
为 QListView 创建上下文菜单并为特定的 QListViewItem 运行此对话框不是很容易吗?
I think you can do smf like this:
But i think you doin smf wrog if you have to clone QListView.
Is't it easy to make context menu for QListView and run this dialog for specific QListViewItem?