[Qt-interest] Extracting MDI windows

BRM bm_witness at yahoo.com
Mon Feb 21 19:51:01 CET 2011


I'm doing something similar, but using Mouse Double-click Event to promote back 
and forth and not using MDI though the tricks should work there too.
Simply put, I do:

1. Detect the event that I want to use to insert/extract the Window (e.g. 
Double-Click)
2. When extracting, just set the widget's parent to NULL and tell it to show().
3. When inserting, set the widget's parent to the previous parent and tell it to 
show().

I initially did this using two classes: (i) a special layout class that worked 
with (ii) a special widget class. The widget class would detect the change, and 
the layout class would implement it.

I'm now playing around with a simpler solution but haven't tested it yet that is 
based on the QMdiArea/QMdiSubWindow relationship - a single class that is used 
to insert the widget into the
interface, and filters for the double-click event, extracting and inserting the 
widget as appropriate. The nice thing about this new approach is that it would 
work with any layout, and not all
widgets would have to do it either.

In both cases, whoever is inserting needs to know which widget to use as the 
parent - so you do have to track it. I suspect that you will want to follow my 
second approach as it is simpler and should work
easily with what you are doing too. Check into installEventFilter() for details.

So it's something like the following:

class myWidgetClass : public QWidget {
    myWidgetClass(QWidget* _parent) : QWidget(_parent) { myWidget = NULL; }
    void setWidget(QWidget* _widget) {
        myWidget = _widget;
        // install event filter or other detection mechanism here
        onInsert();
    }
    QWidget* widget() const { return myWidget; }
...
protected slots:
    void onExtractWidget() {
        myWidget->setParent(NULL):
        myWidget->show();
     }
    void onInsertWidget() {
        myWidget->setParent(this);
        myWidget->show();    // you might not need this line but it doesn't hurt
    }
protected:
    QWidget* myWidget;
};

HTH,

Ben


>
>From: lbutler3 <lbutler3 at comcast.net>
>To: qt-interest at qt.nokia.com
>Sent: Mon, February 21, 2011 11:08:56 AM
>Subject: [Qt-interest] Extracting MDI windows
>
>Is there a way to extract windows from an MDI area and promote to full windows 
>in the application?
>
>
>I've tried the following:
>
>
>void MainWindow::on_actionNew_triggered()
>{
>    m_textwins.append(new QPlainTextEdit(ui->mdiArea));
>    ui->mdiArea->addSubWindow(m_textwins.last());
>    m_textwins.last()->show();
>}
>void MainWindow::on_actionExtractMDI_triggered()
>{
>    QMdiSubWindow *sw = ui->mdiArea->currentSubWindow();
>    QWidget *win = sw->widget();
>    win->setParent(this, Qt::Dialog);
>    win->show();
>    ui->mdiArea->removeSubWindow(sw);
>}
>
>
>which seems to work until the re-parented QPlainTextWindow is resized, when 
>another window magically  appears.  This new window seems to be a new 
>application window without the application menus attached.
>
>
>Any suggestions would be welcome.
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110221/84b85d56/attachment.html 


More information about the Qt-interest-old mailing list