脱最大似然的把元素上面的抽屉

0

的问题

我在努力与一个非常基本的问题..

使用夸脱落5.15.2:

我们有一个简单的应用程序的一个主窗口和2-3子窗口(1职等下降的主要). 主窗口包括一个内容的项目、标题和一些菜单-翼分布在主要的窗口。 迄今为止的子网页的开设了一个抽屉元。

但是,抽屉复盖翼和头一次打开,我们需要重新instanciate翼和头在抽屉里有它明显可见。 这不是真的很好。 是否有任何方法来定义z级别上的抽屉被打开? (显然设置z不工作)。


Item{
  id: id_mainWindow
  z: 0
  Drawer{
    id: id_subMenu1
    anchors.fill: parent
    z: 1
    
    /* Not so nice workaround */
    Button{
      id: id_subClose
      z: 100
      onClicked{
        id_subMenu1.close()
      }
    }
  }

  /* Unfortunately, this one gets hidden once, the drawer is open */
  Button{
    id: id_subOpenClose
    z: 100
    onClicked{
      if( id_subMenu1.open ){
        id_subMenu1.close()
      } else {
        id_subMenu1.open()
      }
    }
  }

}
qml qt qt5.15
2021-11-19 07:31:58
1

最好的答案

0

我建议一个 Drawer 不是正确的组件,用于这项工作,因为它在技术上是一个 Popup. 这可能是值得检查的 签栏 件代替。

不过这里重写代码,以便你 Drawer 打开没有遮盖你的 id_subOpenClose 按钮。

import QtQuick
import QtQuick.Controls
import QtQuick.Controls.Material

Rectangle {
    id: id_mainWindow
  
    anchors.fill: parent
  
    Drawer {
        id: id_subMenu1
    
        /*
        Set the Drawer's height and y position so that it does not cover your button
        */
        y: id_subOpenClose.height
        height: id_mainWindow.height - id_subOpenClose.height
        width: id_mainWindow.width

        // Do not dim background
        dim: false
        
        // Set this to zero if you want no shadow
        Material.elevation: 2
    
        edge: Qt.RightEdge
    
        Label {
            text: 'Hello World'
            anchors.centerIn: parent
        }
    }

    /* 
    This is your header button that was getting hidden
    Here it stays as if it were part of a global header and does not get hidden by
    the Drawer.
    */
    Button{
        id: id_subOpenClose
        text: id_subMenu1.visible? 'close': 'open'
        onClicked: id_subMenu1.visible? id_subMenu1.close(): id_subMenu1.open()
    }
}

对于一个交互式WASM例上看到 在这里.

2021-12-01 15:56:39

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................