QWindow as a parent of QDialog?



  • The main window of my application is QQuickView which is a subclass of QWindow.
    And, I have a preferences QDialog which contains various controls.
    So, I want to lauch QDialog whose parent is set to QQuickView instance.
    However, there's no constructor to accept QWindow instance as parent in QDialog as you know.
    Is there any way to give QWindow as a parent of QDialog?


  • Moderators

    Hi @xylosper,

    As far as I know, you can't make a QWindow the parent of a QWidget. However, are you willing to implement your dialog using a Dialog QML type?



  • @JKSH

    For now, I don't consider that because I'm trying to reuse code which I've written and maintained before Qt 5.
    Also, it contains lots of custom controls and it's really painful to rewrite all of them into QML, especially model/view/delegate parts.

    Thank you for answer.



  • You can't mix QWidget in QWindow. You can do other way round.



  • @dheerendra

    I'm not trying to 'mix QWidget in QWindow'.
    A dialog never will be mixed with other widget or window.
    It is always top-level widget.
    Setting a parent to dialog means the dialog does not have a separated taskbar item and that's what I want to achieve.

    By the way, I found 'QWindow::setTransientParent()' and I could've achieved my goal by setting a QWindow instance as transient parent of dialog's windowHandle().

    QWindow w;
    w.show();
    QDialog dlg;
    dlg.winId(); // ensure to create native window
    dlg.windowHandle()->setTransientParent(&w);
    dlg.exec();


  • There is a static function of QWidget that will create a container widget with a QWindow as a parent.
    QWidget* QWidget::createWindowContainer(QWindow *,...)

    Once you have the widget container this can be the parent of any other dialogs or widgets you need to add.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.