qt - 使用 Qt Creator 调整应用程序的大小是错误和滞后的
问题描述
所以正如标题所说,我无法让我的 GUI 停止滞后,例如,当我拖动 GUI 的左侧时,它以一种奇怪的方式拉伸并且动画缓慢,我的光标也到达了 GUI 之前的点并且大约需要半秒钟才能达到所需的确切形状。这是四个 8 种可能的调整大小选项(左、右、右下等 ..)的情况。
我正在使用 Qt Creator 并用 QML 编写。我正在使用这个函数来调整大小:
mainWindow.startSystemResize("some edge");
并且以下标志应用于窗口应用程序:
flags: Qt.Window | Qt.FramelessWindowHint
编辑 所以我做了以下示例代码,它有同样的问题:
import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15
Window {
id: mainWindow
width: 1000
height: 580
minimumWidth: 800
minimumHeight: 500
visible: true
color: "#00000000"
title: qsTr("Test")
//removing the windows default bar
flags: Qt.Window | Qt.FramelessWindowHint
Rectangle {
id: bg
color: "#2c313c"
anchors.fill: parent
Rectangle {
id: rectangle
x: 205
y: 133
width: 200
height: 200
color: "#e03d3d"
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
}
}
//for resizing using the mouse
property int bw: 5
MouseArea {
id: resizingWindow
anchors.fill: parent
hoverEnabled: true
cursorShape: {
const p = Qt.point(mouseX, mouseY);
const b = bw + 10; // Increase the corner size slightly
if (p.x < b && p.y < b) return Qt.SizeFDiagCursor;
if (p.x >= width - b && p.y >= height - b) return Qt.SizeFDiagCursor;
if (p.x >= width - b && p.y < b) return Qt.SizeBDiagCursor;
if (p.x < b && p.y >= height - b) return Qt.SizeBDiagCursor;
if (p.x < b || p.x >= width - b) return Qt.SizeHorCursor;
if (p.y < b || p.y >= height - b) return Qt.SizeVerCursor;
}
// acceptedButtons: Qt.NoButton // don't handle actual events
DragHandler {
id: resizeHandler
// grabPermissions: TapHandler.TakeOverForbidden
target: null
onActiveChanged: if (active) {
const p = resizeHandler.centroid.position;
const b = bw + 5; // Increase the corner size slightly
let e = 0;
if (p.x < b) { e |= Qt.LeftEdge }
if (p.x >= width - b) { e |= Qt.RightEdge }
if (p.y < b) { e |= Qt.TopEdge }
if (p.y >= height - b) { e |= Qt.BottomEdge }
mainWindow.startSystemResize(e);
}
}
}
}
PS:为了运行它,您需要将代码放入 Qt Creator 中,然后运行 QML 代码并尝试在 8 个方向之一调整大小
解决方案
推荐阅读
- c# - C# 为什么我可以通过属性访问非静态类的方法和属性,而无需先创建该类的实例?
- r - 拆分数据框列表中的列 R
- python - 将张量流数据集输入模型
- scala - ZIO环境建设
- oracle - Coldfusion 将记录插入 Oracle DB
- docker - 错误:无法在 docker-dr-elephant 构建中找到匹配项
- python - 对 numpy 数组的高效操作包含不同大小的行
- load-balancing - 设置 docker-swarm 以使用特定节点作为备份?
- middleware - 在 Lumen 中进行单元测试时跳过授权
- python - 根据 pandas/NumPy 中的多个切片选择子集?