[SOLVED] ToolBar DropShadow - mellow shadow with colored borders



  • I'm trying to create a material design toolbar with a blurred drop shadow.

    The challenge is that I can either create an extremely harsh shadow that looks terrible, or I have to make the borders transparent, which leaves an undesirable white ring around the toolbar.

    I mocked up a quick Qt App to demonstrate the issue. If "transparentborder" is removed, the shadow loses it's blur.

    import QtQuick 2.4
    import QtQuick.Controls 1.3
    import QtQuick.Window 2.2
    import QtQuick.Dialogs 1.2
    import QtQuick.Layouts 1.1
    import QtQuick.Controls.Styles 1.2
    import QtGraphicalEffects 1.0

    ApplicationWindow {
    title: qsTr("Hello World")
    width: 640
    height: 480
    visible: true

    toolBar: ToolBar {
        id: mainToolBar
        width: parent.width
        height: 48
    
        layer.enabled: true
        layer.effect: DropShadow{
            radius: 4
            samples: radius *2
            verticalOffset: 3
            source: mainToolBar
            color: "grey"
            transparentBorder: true
            }
    
        style: ToolBarStyle {
            background: Rectangle {
                id: toolBarRect
                color: "black"
                anchors.fill: parent
                border.color: "black"
            }
        }
    }
    

    }

    I've tried putting the drop shadow against the toolbar rectangle that creates the background color, and I've tried creating another rectangle just for the drop shadow, but nothing seems to work.

    EDIT:

    Figured it out. I anchored the background rectangle to each side individually, and then added a margin of -1 to compensate for the lack of border, with the exception of the bottom, which requires a margin of 0. If the bottom is set to -1 as well, then the harsh shadow returns. It doesn't matter what the shadow looks like on the other 3 sides, since they meet the edge of the window.

        style: ToolBarStyle {
            background: Rectangle {
                id: toolBarRect
                color: "black"
                    anchors {
                        top: parent.top
                        topMargin: -1
                        left: parent.left
                        leftMargin: -1
                        right: parent.right
                        rightMargin: -1
                        bottom: parent.bottom
                        bottomMargin: 0
                    }
            }
        }


Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.