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. using Shape as Pane background gives 1 pixel white line
Qt 6.11 is out! See what's new in the release blog

using Shape as Pane background gives 1 pixel white line

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 2 Posters 1.2k Views 1 Watching
  • 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.
  • mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by
    #1

    Hi all -

    I'm trying to use a Shape (with a LinearGradient) as a background for Panes. For some reason, I'm getting some 1 pixel white lines between my Panes. Is this a bug, or am I doing something wrong?
    Screenshot 2024-11-22 103800.png
    My code:

    // Main.qml
    import QtQuick
    import QtQuick.Controls
    
    ApplicationWindow {
        id: mainWindow
        width: 800
        height: 480
        visible: true
        title: qsTr("Hello World")
        SpaceDashboard {
            id: spaceDashboard
            anchors.fill: parent
        }
    }
    
    // SpaceDashboard.qml
    import QtQuick
    import QtQuick.Controls
    import QtQuick.Layouts
    
    Pane {
        id: spaceDashboard
        padding: 0
        anchors.fill: parent
        background: ScreenBackground {
            bgHeight: spaceDashboard.height
            bgWidth: spaceDashboard.width
        }
        ColumnLayout {
            anchors.fill: parent
            spacing: 0
            Rectangle {
                Layout.preferredHeight: 64
                Layout.fillWidth: true
                color: 'white'
                opacity: 0.2
            }
            Pane {
                id: infoPane
                Layout.preferredHeight: 128
                Layout.fillWidth: true
                padding: 0
                background: ScreenBackground {
                    bgHeight: infoPane.height
                    bgWidth: infoPane.availableWidth
                    homeScreen: true
                }
            }
            Item {
                Layout.fillHeight: true
            }
        }
    }
    
    // ScreenBackground.qml
    import QtQuick
    import QtQuick.Shapes
    
    Shape {
        property bool homeScreen: false
        required property int bgHeight
        required property int bgWidth
        ShapePath {
            fillGradient: homeScreen ? homeScreenGradient : primaryScreenGradient
            startX: 0
            startY: 0
            PathLine {
                relativeX: bgWidth
                relativeY: 0
            }
            PathLine {
                relativeX: 0
                relativeY: bgHeight
            }
            PathLine {
                relativeX: bgWidth * -1
                relativeY: 0
            }
            PathLine {
                relativeX: 0
                relativeY: bgHeight * (-1)
            }
        }
        LinearGradient {
            id: homeScreenGradient
            property double angle: 45.0
            x1: 0
            y1: mainWindow.width * Math.sin(angle)
            x2: mainWindow.width
            y2: 0
            GradientStop { position: 0.42; color: "#161254" }
            GradientStop { position: 0.71; color: "#3c2685" }
            GradientStop { position: 1.07; color: "#0aa9c6" }
        }
    
        LinearGradient {
            id: primaryScreenGradient
            property double angle: 45.0
            x1: 0
            y1: mainWindow.width * Math.sin(angle)
            x2: mainWindow.width
            y2: 0
            GradientStop { position: 0.0; color: "black" }
            GradientStop { position: 1.0; color: "white" }
        }
    }
    

    Thanks for any suggestions. Also, if someone has a simpler way to do this, I'm open to ideas.

    1 Reply Last reply
    0
    • JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by JoeCFD
      #2

      the white border is from ShapePath
      ShapePath {
      fillGradient: homeScreen ? homeScreenGradient : primaryScreenGradient
      startX: 0
      startY: 0
      strokeWidth : 0

      will remove the border.
      Question now is:
      why do you want to draw a border when the pane area is coloured with LinearGradient?

      1 Reply Last reply
      1
      • mzimmersM Offline
        mzimmersM Offline
        mzimmers
        wrote on last edited by mzimmers
        #3

        @JoeCFD said in using Shape as Pane background gives 1 pixel white line:

        why do you want to draw a border when the pane area is coloured with LinearGradient

        I don't want to draw a border. This is the only way I know to define the boundaries of the Shape.

        Using the strokeWidth property didn't seem to change anything. EDIT: when I set the strokeWidth to -1, it now works.

        JoeCFDJ 1 Reply Last reply
        0
        • mzimmersM mzimmers

          @JoeCFD said in using Shape as Pane background gives 1 pixel white line:

          why do you want to draw a border when the pane area is coloured with LinearGradient

          I don't want to draw a border. This is the only way I know to define the boundaries of the Shape.

          Using the strokeWidth property didn't seem to change anything. EDIT: when I set the strokeWidth to -1, it now works.

          JoeCFDJ Offline
          JoeCFDJ Offline
          JoeCFD
          wrote on last edited by
          #4

          @mzimmers I tested your code with strokeWidth : 0 on Ubuntu 22.04 and Qt 6.8. 0 is OK.

          1 Reply Last reply
          0
          • mzimmersM Offline
            mzimmersM Offline
            mzimmers
            wrote on last edited by
            #5

            Good to know. I'm running 6.5.3 on Windows 11. Thanks for pointing me in the right direction, though.

            1 Reply Last reply
            0
            • mzimmersM mzimmers has marked this topic as solved on

            • Login

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