0

私は非常に基本的な質問に苦労しています..

QT 5.15.2 の使用:

1 つのメイン ウィンドウと 2 ~ 3 つのサブウィンドウ (メインから 1 レベル下) を持つ単純なアプリケーションがあります。メイン ウィンドウは、コンテンツ アイテム、ヘッダー、およびメイン ウィンドウ全体に分散されたいくつかのメニュー フラップで構成されます。これまでのところ、サブページは引き出し要素で開かれていました。

ただし、引き出しは一度開くとフラップとヘッダーをオーバーレイするため、引き出し内でフラップとヘッダーを再インスタンス化して表示できるようにする必要があります。これは本当にいいことではありません。引き出しが開かれる 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()
      }
    }
  }

}
4

1 に答える 1

0

Drawer技術的には であるため、このジョブには適切なコンポーネントではないことをお勧めしPopupます。代わりに、 TabBarコンポーネントをチェックアウトする価値があるかもしれません。

それにもかかわらず、ボタン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-01T15:56:39.063 に答える