首页 > 解决方案 > 使用 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 个方向之一调整大小

标签: qtqmlqtquick2qt-designer

解决方案


推荐阅读