[英]Moving a widget inside a layout C++ QT
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
我的主要小部件在
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.我需要移动子小部件
quickWidgettum
,它只是父小部件中的不倒翁。
The parent widget mstrWnd
is everything else on screen.父小部件
mstrWnd
是屏幕上的所有其他内容。
Here the C++ code:这里的 C++ 代码:
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:这里是 QML 部分:
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这一行影响了小部件 anchors.centerIn: parent 的位置
Removing it from the QML file fixed my issue从 QML 文件中删除它修复了我的问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.