'Unexpected margin using setGeometry to fill a widget to a QML window
I managed to embed a widget into a QML window by setting its parent to qml root window. But I'm having trouble fullfil the widget to QML window.
I'm connecting QML window size change signal to my widget resize slot, but I get a const horizontal and vertical magin like this (the white margin)
It seems as if the widget has an unexpected shifting
Strangely, the first time setGeometry works fine on window's first show.
//main.qml
import QtQuick
import QtQuick.Window
import QtQuick.Controls
Window {
signal sizeChange(int x, int y, int width, int height)
visible: true
width: 1920
height: 1080
onSizeChange: {
cefWindow.resizeCEFWindow(x, y, width, height)
console.debug(width, height)
}
onWidthChanged: sizeChange(0, 0, width, height)
onHeightChanged: sizeChange(0, 0, width, height)
}
----------------------------------------------------------------
//main.cpp
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QQmlApplicationEngine engine("qrc:/main.qml");
QObject *QmlObj = engine.rootObjects().first();
QWindow *QmlWindow = qobject_cast<QWindow *>(QmlObj);
auto cefWindow = new Form;
engine.rootContext()->setContextProperty("cefWindow", cefWindow);
cefWindow->setGeometry(0, 0, QmlWindow->width(), QmlWindow->height());
// mywi.setProperty("_q_embedded_native_parent_handle", QVariant(parent_HWND));
cefWindow->winId();
cefWindow->windowHandle()->setParent(QmlWindow);
cefWindow->show();
return app.exec();
}
----------------------------------------------------------------
// my widget
Form::Form(QWidget *parent) : QWidget(parent),
ui(new Ui::Form)
{
ui->setupUi(this);
ui->label->setStyleSheet("background: red");
}
void Form::resizeCEFWindow(int x, int y, int width, int height)
{
qDebug() << y << " " << width << " " << height;
setGeometry(0, 0, width, height);
}
Form::~Form()
{
delete ui;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
