Qt QML Öğeyi bir Çekmecenin üzerine yerleştirin

0

Soru

Çok basit bir soruyla uğraşıyorum..

QT 5.15.2'yi kullanma:

Bir ana pencere ve 2-3 alt pencere (ana pencereden 1 seviye aşağı) ile basit bir uygulamamız var. Ana pencere, bir içerik öğesi, bir başlık ve ana pencereye dağıtılmış bazı menü kanatlarından oluşur. Şimdiye kadar alt sayfalar bir çekmece elemanı ile açıldı.

Bununla birlikte, çekmece açıldıktan sonra kanatları ve başlığı üst üste bindirir ve görünür olması için kanatları ve başlığı çekmecenin içine yeniden yerleştirmemiz gerekir. Bu gerçekten hoş değil. Çekmecenin açıldığı z seviyesini tanımlamanın bir yolu var mı? (görünüşe göre z ayarı çalışmıyor).


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

En iyi cevabı

0

Bir öneririm Drawer teknik olarak bu iş için doğru bileşen değil mi Popup. Bunun yerine TabBar bileşenini kontrol etmeye değer olabilir.

Yine de, kodunuzun yeniden yazılması, böylece Drawer kaplamadan açılır id_subOpenClose düğme.

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

Yukarıdakilerin etkileşimli bir WASM örneği için buraya bakın.

2021-12-01 15:56:39

Diğer dillerde

Bu sayfa diğer dillerde

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