qml窗口拖拽闪烁

以下是右边框示例

 MouseArea {
        id: mouseArea
        acceptedButtons: Qt.LeftButton //只处理鼠标左键
        property point clickPos: "0,0"
        cursorShape: Qt.SizeHorCursor
        anchors.top:parent.top
        anchors.right:parent.right
        anchors.topMargin: 30
        width: 10
        height: parent.height
        anchors.rightMargin: 0
        //hoverEnabled: true
        onPressed: { //接收鼠标按下事件
            clickPos  = Qt.point(mouse.x,mouse.y)
        }
        onPositionChanged: { //鼠标按下后改变位置
            //鼠标偏移量
            var delta = Qt.point(mouse.x-clickPos1.x, mouse.y-clickPos1.y)
            //如果mainwindow继承自QWidget,用setPos
            mainWindow.width = mainWindow.width + mouse.x-clickPos1.x
        }
    }

用以上代码进行拉伸的时候窗口会出现闪烁现象,经过一番仔细的搜索,在cpp文件中加入下面代码就可以解决

QCoreApplication::setAttribute(Qt::AA_UseSoftwareOpenGL);

你可能感兴趣的:(qml窗口拖拽闪烁)