QML无边框窗体怎么能调整大小?



  • 具体来说就是,窗口右下角那个东西用来调整大小的,但是无边框之后那个东西没有了

    ApplicationWindow {
        flags:  Qt.Window|Qt.FramelessWindowHint
    }
    

    无边框是这样设置的


  • 网站研运

    @hezhongfeng 还是可以通过MouseArea捕捉鼠标按下事件,然后借此通过修改ApplicationWindow的width和height可以制作更改窗口大小的小功能。



  • @jcy
    明白了,看来只能自己弄,并没有原生部件提供.Thanks



  • @hezhongfeng 写了一些代码。如下。希望能够提供一些思路给你。

    如下是: BackgroundItem.qml

    import QtQuick 2.5
    import QtQuick.Controls 1.4
    
    Item {
        id: backgoundItem
        property ApplicationWindow mainWindow: null
        property real windowBorderWidth: 10
    
        readonly property rect leftTop:  Qt.rect(0, 0, windowBorderWidth, windowBorderWidth) // left top
        readonly property rect leftSide: Qt.rect(0, windowBorderWidth, windowBorderWidth, backgoundItem.height - 2 * windowBorderWidth) // left side
        readonly property rect leftBottom: Qt.rect(0, backgoundItem.height-windowBorderWidth, windowBorderWidth, windowBorderWidth) // left bottom
        
        readonly property rect topSide: Qt.rect(windowBorderWidth, 0, backgoundItem.width-2*windowBorderWidth, windowBorderWidth) // top side
        readonly property rect center: Qt.rect(windowBorderWidth, windowBorderWidth, backgoundItem.width-2*windowBorderWidth, backgoundItem.height - 2 * windowBorderWidth) // center
        readonly property rect bottomSide: Qt.rect(windowBorderWidth, backgoundItem.height-windowBorderWidth,
                                                   backgoundItem.width-2*windowBorderWidth,  backgoundItem.width-2*windowBorderWidth) // bottom
        
        readonly property rect rightTop: Qt.rect(backgoundItem.width-windowBorderWidth, 0, windowBorderWidth, windowBorderWidth) // right top
        readonly property rect rightSide: Qt.rect(backgoundItem.width-windowBorderWidth, windowBorderWidth, windowBorderWidth, backgoundItem.height - 2 * windowBorderWidth) // right side
        readonly property rect rightBottom: Qt.rect(backgoundItem.width-windowBorderWidth, backgoundItem.height-windowBorderWidth, windowBorderWidth, windowBorderWidth) // left bottom
    
        Rectangle {
            anchors.fill: parent
            // anchors.margins: windowBorderWidth
            color: "white"
            border.width: 1
            border.color: "#ccc"
            // 最底层
        }
    
        MouseArea {
            anchors.fill: parent
            hoverEnabled: true
            property point oldPosition
    
            Component.onCompleted: {
                oldPosition = Qt.point(mouseX, mouseY);
            }
    
            onPositionChanged: {
                var currentPosition = Qt.point(mouse.x, mouse.y);
    
                var p = Qt.point(mouse.x, mouse.y);
    
                if(rectContains(leftTop, p) || rectContains(rightBottom, p)) {
                    cursorShape = Qt.SizeFDiagCursor;
                    if(pressed) {
    
    //                    mainWindow.x = mouse.x;
    //                    mainWindow.y = mouse.y;
                        var height_d = currentPosition.y - oldPosition.y;
                        var width_d =  currentPosition.x - oldPosition.x;
                        mainWindow.x += width_d
                         mainWindow.y += height_d
                        mainWindow.width += width_d;
                        mainWindow.height += height_d;
    
    
                        //console.log("pressed")
    
                    }
    
                    return;
                } else if(rectContains(leftBottom, p) || rectContains(rightTop, p)) {
                    cursorShape = Qt.SizeBDiagCursor;
                    return;
                } else if(rectContains(topSide, p) || rectContains(bottomSide, p)) {
                    cursorShape = Qt.SizeVerCursor;
                    return;
                } else if(rectContains(rightSide, p) || rectContains(leftSide, p)) {
                    cursorShape = Qt.SizeHorCursor;
                    return;
                }
    
                cursorShape = Qt.ArrowCursor;
                oldPosition = Qt.point(mouse.x, mouse.y);
            }
    
    
        }
        function rectContains(rect, point) {
            var x_d = point.x - rect.x;
            var y_d = point.y - rect.y;
    
            return (x_d > 0 && x_d < rect.width)
                    && (y_d > 0 && y_d < rect.height);
        }
    }
    

    main.qml 中使用:

    import QtQuick 2.5
    import QtQuick.Controls 1.4
    import QtQuick.Controls.Styles 1.4
    
    
    ApplicationWindow {
        id: app
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
    
        flags:  Qt.Window|Qt.FramelessWindowHint
    
        property real windowBorderWidth: 10
    
        style: ApplicationWindowStyle {
            background:
                BackgoundItem {
                id: backgoundItem
                 windowBorderWidth: app.windowBorderWidth
                 mainWindow: app
            }
        }
    
        Rectangle {
            anchors.fill: parent
            anchors.margins: 10
            color: "yellow"
            focus: true
            Keys.onEscapePressed: Qt.quit()
        }
    }
    

    这样。当鼠标在窗体边上时,就是改变鼠标图标,然后实现一些逻辑即可。不过上诉代码仅仅只是思路,具体的代码逻辑需要自行解决。



  • @qyvlikQML无边框窗体怎么能调整大小? 中说:

    就是改变鼠标图标,然后实现一些逻辑即可

    谢谢。
    在官方论坛也问了,基本还是得自己做。
    思路和这个差不多
    目前还是学习阶段



  • @hezhongfeng 你这个问题解决了吗?我也在寻求相关的资料。菜鸟表示很头疼


 

走马观花

最近的回复

  • @bladesero Blender 在角色建模和渲染这些方面的确比较强。😄

    我们的软件还在发展中呢。
    18da2116-2055-47c1-8317-1ccde17dfcc0-image.png

    阅读更多
  • untitled.jpg figure角色(WIP2).jpg
    TIM截图20190117184210.png
    使用的软件是blender,zbrush和substance painter

    阅读更多
  • 背景:如果需要qml显示循环list,一般是用3个ListView循环交替,实现伪循环,期间逻辑复杂,容易出错,PathView本身自带循环,所以考虑用PathView实现循环

    设计:PathView显示5条数据,按照垂直List一个个排好顺序,由于收尾移动时候会空白穿帮,所以用clip控制显示中间三条数据

    滚动控制:currentIndex,decrementCurrentIndex(),incrementCurrentIndex()

    代码:

    Item{ id: item1 property int myIndex: 0 property int onePageCount: 3 property real oneHeight: 72 property real oneWidth: 580 property int isCurrentListView: 1 //0,1,2 property bool isAdd: true //direction,down=true,up=false property int hightlightIndex: 0 property int currentIndexPathView: 0 //use this Item{ id: itemClip width: item1.oneWidth height: item1.oneHeight*3 clip: true PathView { id: listView1 width: item1.oneWidth model: listModelSpeedWarning delegate: delegeteLine pathItemCount: item1.onePageCount+2 interactive: false path: Path { startX: item1.oneWidth/2 startY: -item1.oneHeight/2 PathQuad { x: item1.oneWidth/2; y: item1.oneHeight*0+item1.oneHeight/2; controlX: item1.oneWidth/2; controlY: item1.oneHeight*0+item1.oneHeight/2 } PathQuad { x: item1.oneWidth/2; y: item1.oneHeight*1+item1.oneHeight/2; controlX: item1.oneWidth/2; controlY: item1.oneHeight*1+item1.oneHeight/2 } PathQuad { x: item1.oneWidth/2; y: item1.oneHeight*2+item1.oneHeight/2; controlX: item1.oneWidth/2; controlY: item1.oneHeight*2+item1.oneHeight/2 } PathQuad { x: item1.oneWidth/2; y: item1.oneHeight*3+item1.oneHeight/2; controlX: item1.oneWidth/2; controlY: item1.oneHeight*3+item1.oneHeight/2 } PathQuad { x: item1.oneWidth/2; y: item1.oneHeight*4+item1.oneHeight/2; controlX: item1.oneWidth/2; controlY: item1.oneHeight*4+item1.oneHeight/2 } } Component.onCompleted: { listView1.currentIndex = -1 } } } }

    问题:windows下测试,按住按键不松手,list滚动会卡住,松手后恢复正常,看来list不能滚动太快

    阅读更多
  • H

    @青山白云 只是为了替换GIF,不过目前已经解决加载问题

    阅读更多

关注我们

微博
QQ群











召唤伊斯特瓦尔