Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to preserve strokes after canvas resized

How to preserve strokes after canvas resized

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 572 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rock wang
    wrote on last edited by
    #1

    When the canvas resized, strokes will be clear. How to preserve them when adjust size of the canvas?
    (the canvas fill the window and the window can be resized by user)

    ODБOïO 1 Reply Last reply
    0
    • R rock wang

      When the canvas resized, strokes will be clear. How to preserve them when adjust size of the canvas?
      (the canvas fill the window and the window can be resized by user)

      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by
      #2

      @rock-wang hi,
      Could you plz show your code exemple ?
      I binded my canvas size to my windows size and when i'm resizing everything is preserved for me

      1 Reply Last reply
      1
      • R Offline
        R Offline
        rock wang
        wrote on last edited by
        #3
        import QtQuick 2.9
        import QtQuick.Window 2.2
        import QtQuick.Controls 1.5
        import QtQuick.Layouts 1.3
        import QtQuick.Controls.Styles.Desktop 1.0
        import QtQuick.Extras 1.4
        
        Window {
            visible: true
            width: 800
            height: 600
            //flags:Qt.FramelessWindowHint
            title: qsTr("优能视频客户端")
        
            ColumnLayout{
                id: mainLayout
                anchors.fill: parent
                Rectangle{
                    width: 30
                    height: 30
                    color:'gray'
                    Layout.alignment: Qt.AlignLeft | Qt.AlignTop
                    Layout.fillWidth: true
                    RowLayout {
                        id: rowLayout
                        anchors.fill: parent
                        Image {
                            id: imgIcon
                            sourceSize.height: 16
                            sourceSize.width: 16
                            fillMode: Image.Stretch
                            Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
                            source: "qrc:/images/Logo.png"
                        }
                        Text {
                            text: "优能视频客户端"
                            Layout.fillWidth: true
                        }
        
                        Image {
                            id: imgMin
                            sourceSize.height: 16
                            sourceSize.width: 16
                            fillMode: Image.Stretch
                            Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
                            source: "images/minimizeNormal.png"
                        }
        
                        Image {
                            id: imgMax
                            sourceSize.height: 16
                            sourceSize.width: 16
                            fillMode: Image.Stretch
                            Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
                            source: "images/max_2.png"
                        }
        
                        Image {
                            id: imgClose
                            sourceSize.height: 16
                            sourceSize.width: 16
                            fillMode: Image.Stretch
                            Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
                            source: "images/closeNormal.png"
                        }
                    }
                }
        
                Canvas{
                    property real lastX
                    property real lastY
                    id: canvas
                    Layout.fillHeight: true
                    Layout.fillWidth: true
                    onPaint: {
                        var ctx = this.getContext("2d")
                        ctx.lineWidth = 5.0
                        ctx.strokeStyle = 'red'
                        ctx.beginPath()
                        ctx.moveTo(lastX, lastY)
                        lastX = area.mouseX
                        lastY = area.mouseY
                        ctx.lineTo(lastX, lastY)
                        ctx.stroke()
                    }
                    MouseArea{
                        id:area
                        anchors.fill: parent
                        onPressed: {
                            canvas.lastX = mouseX
                            canvas.lastY  =mouseY
                        }
                        onPositionChanged: {
                            canvas.requestPaint()
                        }
                    }
                }
        
            }
        }
        
        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved