I am having trouble moving a widget inside another widget:
It may be simple but I just can't get it:
My main widget is in a QHBoxlayout
My child widget is within the main widget's layout (the tumbler highlighted in yellow in the pic) which I need to relocate
I need to move the child widget quickWidgettum
which is just the tumbler within the parent widget.
The parent widget mstrWnd
is everything else on screen.
Here the C++ code:
mstrWnd = new QWidget;
mstrWnd->setObjectName(STR_MASTER_WINDOW_NAME);
mstrWnd->setWindowTitle(getSettingI(MSTR_APP_TITLE));
mstrWnd->setGeometry(getSettingI(MSTR_APP_X).toInt(),
getSettingI(MSTR_APP_Y).toInt(),
getSettingI(MSTR_APP_WIDTH).toInt(),
getSettingI(MSTR_APP_HEIGHT).toInt());
mstrWnd->setWindowFlags(Qt::FramelessWindowHint | Qt::Window);
mstrWnd->setWindowState(Qt::WindowFullScreen);
QHBoxLayout* laos = new QHBoxLayout();
mstrWnd->setLayout(laos);
QQuickView* quickView = new QQuickView(QUrl::fromLocalFile(QDir::currentPath() + "\\Resources\\videos\\aos.qml"));
quickView->setResizeMode(QQuickView::SizeRootObjectToView);
quickWidgettum = new QWidget;
quickWidgettum = QWidget::createWindowContainer(quickView);
laos->addWidget(quickWidgettum);
And here the QML part:
import QtQuick 2.12
import QtQuick.Window 2.2
import QtQuick.Controls 2.12
Rectangle {
width: frame.implicitWidth + 10
height: frame.implicitHeight + 10
function formatText(count, modelData) {
var data = count === 12 ? modelData + 1 : modelData;
return data.toString().length < 2 ? "0" + data : data;
}
FontMetrics {
id: fontMetrics
}
Component {
id: delegateComponent
Label {
text: formatText(Tumbler.tumbler.count, modelData)
opacity: 1.0 - Math.abs(Tumbler.displacement) / (Tumbler.tumbler.visibleItemCount / 2)
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
font.pixelSize: fontMetrics.font.pixelSize * 1.25
}
}
Frame {
id: frame
padding: 0
anchors.centerIn: parent
Row {
id: row
Tumbler {
id: hoursTumbler
model: 12
delegate: delegateComponent
}
Tumbler {
id: minutesTumbler
model: 60
delegate: delegateComponent
}
Tumbler {
id: amPmTumbler
model: ["AM", "PM"]
delegate: delegateComponent
}
}
}
}
This line was affecting the position of the widget anchors.centerIn: parent
Removing it from the QML file fixed my issue
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.