Search code examples
qtqmlqt-quickqtquick2

QtQuick Rectangle control what borders show?


How to draw a Rectangle and control if it is to show left or right borders or both using QtQuick 2?


Solution

  • There is a border property in the Rectangle that allows you to add a border to your element. The issue is that you can't show only the left or the right border with it. To do that you have to add extra elements in your Rectangle to represent a border.

    Rectangle {
        width: 100
        height: 200
        color: "blue"
    
        Rectangle {
            id: borderLeft
            width: 1
            height: parent.height
            anchors.left: parent.left
            color: "red"
        }
    
        Rectangle {
            id: borderRight
            width: 1
            height: parent.height
            anchors.right: parent.right
            color: "red"
        }
    }