Qt QML Pus element de mai sus-un Sertar

0

Problema

Eu sunt luptă cu o întrebare de bază..

Folosind QT 5.15.2:

Avem o aplicație simplă cu o singură fereastră principală și 2-3 sub-fereastră (1 nivel mai jos de principala). Fereastra principală constă dintr-un articol de conținut, un antet și un meniu-clape distribuite în fereastra principală. Până în Prezent, sub-pagini au fost deschise cu un sertar element.

Cu toate acestea, sertar suprapuneri clapele și antet odată deschis și avem nevoie de a re-instanciate clapele și antet în sertar pentru a fi vizibil. Acest lucru nu este foarte frumos. Există vreo modalitate de a defini z-nivelul la care sertarul este deschis? (se pare că setarea z nu funcționează).


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

Cel mai bun răspuns

0

Aș sugera că o Drawer nu este drept componentă pentru acest loc de muncă, deoarece este punct de vedere tehnic un Popup. Ar putea fi în valoare de verificarea TabBar componentă în loc.

Cu toate acestea, aici este o re-scriere de cod, astfel încât dvs. Drawer deschide fără a acoperi id_subOpenClose buton.

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

Pentru un interactiv WASM exemplu de mai sus a se vedea aici.

2021-12-01 15:56:39

În alte limbi

Această pagină este în alte limbi

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