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. ActiveFocus draws outside rounded menu corners
Forum Updated to NodeBB v4.3 + New Features

ActiveFocus draws outside rounded menu corners

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 307 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.
  • Q Offline
    Q Offline
    qthackerman
    wrote on last edited by
    #1

    Hi!
    I'm trying to make a menu with rounded corners using components from QtQuick.Controls 2.15.
    However, the activeFocus background from the MenuItems is not rounded, and so the corners of the MenuItem background ends up sticking out from the menu background for the top and bottom choice when hovered over.

    Is it possible to ensure that the MenuItem background does not protrude from the Menu background?

    Thanks for any responses, and please ask for more information if needed. I'm new to qt :)

    1 Reply Last reply
    0
    • MarkkyboyM Offline
      MarkkyboyM Offline
      Markkyboy
      wrote on last edited by
      #2

      Post your working code, it's the quickest way to get a response.

      Don't just sit there standing around, pick up a shovel and sweep up!

      I live by the sea, not in it.

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qthackerman
        wrote on last edited by
        #3

        I'll keep that in mind next time, thanks.

        It turns out what I wanted had a name, clipping. You can set clip: true, and that should prevent the menuitems' backgrounds from drawing outside of the menu itself. However, due to performance concerns, clip regions can only be rectangular so that did not solve the problem in this case.

        The solution was to redefine the background of the menuItems like this:
        (keep in mind that I'm still a noob, so while this code solves this specific problem, it might not be so great in other ways)

        background: Item {
                height: root.implicitHeight 
                width: root.implicitWidth
                anchors.bottom: root.bottom
                opacity: root.activeFocus ? 0.5 : 0
                layer.enabled: true
                Rectangle {
                    implicitHeight: 0.5 * root.implicitHeight
                    color: "#000000"
                    opacity: (root.activeFocus && (isFirst || isLast)) ? 1 : 0
                    anchors.top: isFirst ? undefined : roundRect.top
                    anchors.right: roundRect.right
                    anchors.left: roundRect.left
                    anchors.bottom: isFirst ? roundRect.bottom : undefined
                    visible: opacity
                }
                Rectangle {
                    id: roundRect
                    radius: (isLast || isFirst) ? 15 : 0
                    implicitHeight: root.implicitHeight
                    color: "#000000"
                    anchors.fill: parent
                }
            }
        
        1 Reply Last reply
        1

        • Login

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