Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] ToolBar DropShadow - mellow shadow with colored borders

[SOLVED] ToolBar DropShadow - mellow shadow with colored borders

Scheduled Pinned Locked Moved General and Desktop
dropshadowtoolbartransparentbordmaterial design
1 Posts 1 Posters 1.6k 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.
  • mchouseM Offline
    mchouseM Offline
    mchouse
    wrote on last edited by mchouse
    #1

    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
                    }
            }
        }
    
    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