Custom behavior for Drawer



  • Hi, I have an application with a StackView as main layout and a Drawer. I want the Drawer only be accessed when the StackView has only one component. According to QtQuick Controls 2's documentation I can do it setting the property dragMargin of Drawer to 0 or a less value. So I did this

    Drawer {
    id: drawer
    dragMargin: rootLayout.depth > 1 ? 0 : Qt.styleHints.startDragDistance
    ...
    }

    StackView {
    id: rootLayout
    ...
    }

    But does not work at all, because you can access dragging your finger from the edge of the phone. The only thing that achievement is to drastically reduce the area to get the Drawer.
    I appretiate the help, because I have a Page that insert into the StackView containing a SwipeView with content close to the edges and has conflicts with the Drawer that is not disabled. I tried setting 0 and -10 to dragMargin, but noting


  • Moderators

    Hi! How about disabling the Drawer?

    Drawer {
       id: drawer
       enabled: rootLayout.depth == 0
       onEnabledChanged: dragMargin = enabled ? Qt.styleHints.startDragDistance : 0
    }


  • @Wieland
    The documentation and the compiler say that the property does not exist, which is strange because all components have always brought this property


  • Moderators

    @Camilo-del-Real Oh, sry. Then maybe visible should do the same.



  • @Wieland
    If I use

    Drawer {
    visible: appContentManager.depth == 1
    onVisibleChanged: dragMargin = visible ? Qt.styleHints.startDragDistance : 0
    }

    the drawer is always show at start up (it is not something to be) and with the treatment of onVisibleChanged the Drawer always has 0 in dragMargin when is hidden, which causes only be difficult to show it with draggind



  • If it's possible to drag a drawer open when it has drag margin set to 0, then please report a bug with appropriate details about the platform and device: https://bugreports.qt.io



  • @jpnurmi
    Well, I found a temporary solution while the original idea is fixed with dragMargin. Making the width is 0 can disable the Drawer, but only with the combination of width and dragMargin, if only use width, is still possible show a Drawer (an empty drawer)

    Drawer {
            dragMargin: appContentManager.depth > 1 ? 0 : Qt.styleHints.startDragDistance
            width: appContentManager.depth > 1 ? 0 : Math.min(appRoot.width, appRoot.height) / 3 * 2
    }
    

    I also report the bug
    https://bugreports.qt.io/browse/QTBUG-54629


Log in to reply
 

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