In a Widgets application I want to show a modal dialog designed with QML.
I chose to create a QDialog and insert the QML component inside it. This works well on desktop, but leads to an invisible window on Android. When showing the QDialog with a QPushButton it works as expected, but when I add a QQuickWidget to it, the QDialog becomes invisible.
The mouse area _does_ react to clicks and when I print the sizes at various steps they seem fine. Also, when rotating the device or bringing the app to front, I get to see a glimpse of the QDialog window and it seems to look as expected.
C++ file:
if (layout() != NULL)
delete layout();
setLayout(gridLayout);
gridLayout->addWidget(okButton, 1, 0);
quickWidget = new QQuickWidget();
quickWidget
->setSource
(QUrl("qrc:/Example.qml"));
quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView);
quickWidget->resize(100, 100);
gridLayout->addWidget(quickWidget, 0, 0);
resize(800, 800);
}
AboutDialog::AboutDialog(QWidget *parent) : QDialog(parent) {
if (layout() != NULL)
delete layout();
QGridLayout* gridLayout= new QGridLayout();
setLayout(gridLayout);
okButton = new QPushButton("Close", this);
gridLayout->addWidget(okButton, 1, 0);
quickWidget = new QQuickWidget();
quickWidget->setSource(QUrl("qrc:/Example.qml"));
quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView);
quickWidget->resize(100, 100);
gridLayout->addWidget(quickWidget, 0, 0);
resize(800, 800);
}
To copy to clipboard, switch view to plain text mode
Header file:
class AboutDialog
: public QDialog {public:
private:
QQuickWidget* quickWidget = NULL;
};
class AboutDialog : public QDialog {
public:
AboutDialog(QWidget* parent=0);
private:
QQuickWidget* quickWidget = NULL;
QPushButton* okButton;
};
To copy to clipboard, switch view to plain text mode
QML file:
import QtQuick 2.0
Rectangle {
width: 700
height: 700
color: "#000000"
Rectangle {
height: 600
anchors.left: parent.left; anchors.right: parent.right
anchors.leftMargin: 30; anchors.rightMargin: 30
anchors.bottom: parent.bottom
anchors.bottomMargin: 30
color: "#dd0000"
Text {
anchors.centerIn: parent
font.pixelSize: 30
text: "Quit"
color: "#e0e0e0"
}
MouseArea {
anchors.fill: parent
onClicked: Qt.quit();
}
}
}
import QtQuick 2.0
Rectangle {
width: 700
height: 700
color: "#000000"
Rectangle {
height: 600
anchors.left: parent.left; anchors.right: parent.right
anchors.leftMargin: 30; anchors.rightMargin: 30
anchors.bottom: parent.bottom
anchors.bottomMargin: 30
color: "#dd0000"
Text {
anchors.centerIn: parent
font.pixelSize: 30
text: "Quit"
color: "#e0e0e0"
}
MouseArea {
anchors.fill: parent
onClicked: Qt.quit();
}
}
}
To copy to clipboard, switch view to plain text mode
Added after 14 minutes:
Adb logcat of what seemed relevant (happens on all 3 device I tried with):
#Trigger showing the window, FreeGo is the name of the App.
D/FreeGo ( 8885): void GameSettings::showMenu()
W/libFreeGo.so( 8885): (null):0 ((null)): This plugin does not support grabbing the keyboard
E/Parcel ( 440): Reading a NULL string not supported here.
E/Parcel ( 440): Reading a NULL string not supported here.
W/qdhwcomposer( 318): Excessive delay reading vsync: took 500 ms
W/qdhwcomposer( 318): Excessive delay reading vsync: took 216 ms
D
/FreeGo
( 8885): AboutDialog
::AboutDialog(QWidget*)D
/FreeGo
( 8885): AboutDialog
::AboutDialog(QWidget*) - sizes
: window
: (0 0) 800x800;
D/FreeGo ( 8885): quickWidget:(0 0) 100x100
D/FreeGo ( 8885): virtual int AboutDialog::exec() - sizes: window: (0 0) 800x800;
D/FreeGo ( 8885): quickWidget:(0 0) 100x100
D
/FreeGo
( 8885): virtual void AboutDialog
::resizeEvent(QResizeEvent*) - sizes
: window
: (487 62) 800x800;
D/FreeGo ( 8885): quickWidget:(24 24) 752x595
D
/FreeGo
( 8885): virtual void AboutDialog
::resizeEvent(QResizeEvent*) - sizes
: window
: (487 62) 800x800;
D/FreeGo ( 8885): quickWidget:(24 24) 752x595
W/Adreno-EGL( 8885): <qeglDrvAPI_eglSwapInterval:3818>: EGL_BAD_SURFACE
W/Adreno-EGL( 8885): <qeglDrvAPI_eglSwapInterval:3818>: EGL_BAD_SURFACE
W/qdhwcomposer( 318): Excessive delay reading vsync: took 83 ms
W/WindowManager( 854): Access to extended visibility flags denied: Requires com.sonymobile.permission.SYSTEM_UI_VISIBILITY_EXTENSIONS permission.
W/WindowManager( 854): Access to extended visibility flags denied: Requires com.sonymobile.permission.SYSTEM_UI_VISIBILITY_EXTENSIONS permission.
W/WindowManager( 854): Access to extended visibility flags denied: Requires com.sonymobile.permission.SYSTEM_UI_VISIBILITY_EXTENSIONS permission.
W/WindowManager( 854): Access to extended visibility flags denied: Requires com.sonymobile.permission.SYSTEM_UI_VISIBILITY_EXTENSIONS permission.
W/qdhwcomposer( 318): Excessive delay reading vsync: took 300 ms
W/qdhwcomposer( 318): Excessive delay reading vsync: took 1401 ms
#Press the back button here:
D/FreeGo ( 8885): virtual int AboutDialog::exec() - sizes: window: (487 62) 800x800;
D/FreeGo ( 8885): quickWidget:(24 24) 752x595
D/FreeGo ( 8885): virtual int AboutDialog::exec() - retVal=0
D/FreeGo ( 8885): virtual AboutDialog::~AboutDialog() - sizes: window: (487 62) 800x800;
D/FreeGo ( 8885): quickWidget:(24 24) 752x595
W/WindowManager( 854): Access to extended visibility flags denied: Requires com.sonymobile.permission.SYSTEM_UI_VISIBILITY_EXTENSIONS permission.
W/qdhwcomposer( 318): Excessive delay reading vsync: took 38 ms
W/WindowManager( 854): Access to extended visibility flags denied: Requires com.sonymobile.permission.SYSTEM_UI_VISIBILITY_EXTENSIONS permission.
W/libFreeGo.so( 8885): (null):0 ((null)): Can't find surface 4
W/WindowManager( 854): Access to extended visibility flags denied: Requires com.sonymobile.permission.SYSTEM_UI_VISIBILITY_EXTENSIONS permission.
E/Parcel ( 440): Reading a NULL string not supported here.
#Trigger showing the window, FreeGo is the name of the App.
D/FreeGo ( 8885): void GameSettings::showMenu()
W/libFreeGo.so( 8885): (null):0 ((null)): This plugin does not support grabbing the keyboard
E/Parcel ( 440): Reading a NULL string not supported here.
E/Parcel ( 440): Reading a NULL string not supported here.
W/qdhwcomposer( 318): Excessive delay reading vsync: took 500 ms
W/qdhwcomposer( 318): Excessive delay reading vsync: took 216 ms
D/FreeGo ( 8885): AboutDialog::AboutDialog(QWidget*)
D/FreeGo ( 8885): AboutDialog::AboutDialog(QWidget*) - sizes: window: (0 0) 800x800;
D/FreeGo ( 8885): quickWidget:(0 0) 100x100
D/FreeGo ( 8885): virtual int AboutDialog::exec() - sizes: window: (0 0) 800x800;
D/FreeGo ( 8885): quickWidget:(0 0) 100x100
D/FreeGo ( 8885): virtual void AboutDialog::resizeEvent(QResizeEvent*) - sizes: window: (487 62) 800x800;
D/FreeGo ( 8885): quickWidget:(24 24) 752x595
D/FreeGo ( 8885): virtual void AboutDialog::resizeEvent(QResizeEvent*) - sizes: window: (487 62) 800x800;
D/FreeGo ( 8885): quickWidget:(24 24) 752x595
W/Adreno-EGL( 8885): <qeglDrvAPI_eglSwapInterval:3818>: EGL_BAD_SURFACE
W/Adreno-EGL( 8885): <qeglDrvAPI_eglSwapInterval:3818>: EGL_BAD_SURFACE
W/qdhwcomposer( 318): Excessive delay reading vsync: took 83 ms
W/WindowManager( 854): Access to extended visibility flags denied: Requires com.sonymobile.permission.SYSTEM_UI_VISIBILITY_EXTENSIONS permission.
W/WindowManager( 854): Access to extended visibility flags denied: Requires com.sonymobile.permission.SYSTEM_UI_VISIBILITY_EXTENSIONS permission.
W/WindowManager( 854): Access to extended visibility flags denied: Requires com.sonymobile.permission.SYSTEM_UI_VISIBILITY_EXTENSIONS permission.
W/WindowManager( 854): Access to extended visibility flags denied: Requires com.sonymobile.permission.SYSTEM_UI_VISIBILITY_EXTENSIONS permission.
W/qdhwcomposer( 318): Excessive delay reading vsync: took 300 ms
W/qdhwcomposer( 318): Excessive delay reading vsync: took 1401 ms
#Press the back button here:
D/FreeGo ( 8885): virtual int AboutDialog::exec() - sizes: window: (487 62) 800x800;
D/FreeGo ( 8885): quickWidget:(24 24) 752x595
D/FreeGo ( 8885): virtual int AboutDialog::exec() - retVal=0
D/FreeGo ( 8885): virtual AboutDialog::~AboutDialog() - sizes: window: (487 62) 800x800;
D/FreeGo ( 8885): quickWidget:(24 24) 752x595
W/WindowManager( 854): Access to extended visibility flags denied: Requires com.sonymobile.permission.SYSTEM_UI_VISIBILITY_EXTENSIONS permission.
W/qdhwcomposer( 318): Excessive delay reading vsync: took 38 ms
W/WindowManager( 854): Access to extended visibility flags denied: Requires com.sonymobile.permission.SYSTEM_UI_VISIBILITY_EXTENSIONS permission.
W/libFreeGo.so( 8885): (null):0 ((null)): Can't find surface 4
W/WindowManager( 854): Access to extended visibility flags denied: Requires com.sonymobile.permission.SYSTEM_UI_VISIBILITY_EXTENSIONS permission.
E/Parcel ( 440): Reading a NULL string not supported here.
To copy to clipboard, switch view to plain text mode
Bookmarks