开发者

Delete child from QDialog::layout

开发者 https://www.devze.com 2023-02-05 02:02 出处:网络
class MyDialog : public QDialog { public: MyDialog(QListWidget * w) : m_w(w) { m_layout = new QGridLayout(this);
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 dest开发者_JAVA百科roy, it destroy w too whereas it was remove in the MyDialog's destructor;

Have you got a better solution than clone the QListWidget w ?


I think you can do smf like this:

~MyDialog()
{
   m_w.reparent(main_window);
}

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?

0

精彩评论

暂无评论...
验证码 换一张
取 消