qt - How to design a multi-level fluid layout in QML -


i have designed layout in qml learn more features , have questions on "best practices" in designing such layout. here is:

enter image description here

it columnlayout consisted of 3 rowlayouts, each 1 rectangles. size of each row , rectangle should calculate such as:

  • first row: height = 40%, width = 100%
    • red rectangle filling whole area
  • second row: height = 20%, width = 100%
    • dark-green rectangle: height = 100%, width = 20%,
    • light-green rectangle: height = 100%, width = 80%
  • third row: height = 40%, width = 100%
    • dark-blue rectangle: height = 100%, width = 40%,
    • blue rectangle: height = 100%, width = 20%
    • light-blue rectangle: height = 100%, width = 40%

the qml have came working , in following. have questions it:

  1. i have set width , height percentages using layout.preferredheight: x*parent.height pattern. other options caused issues (e.g. preferredheight caused binding loop warnings). approach correct , efficient?
  2. as hack, set layout.fillwidth: true first element of row #2 , row #3, doesn't make sense me, work. if set width percentage (e.g. layout.preferredwidth: 0.2*parent.width) row collapse width 0. expected behavior? there better workaround?
  3. do have recommendation on layouts? on right path?

here qml code layout:

applicationwindow {     x: 500     y: 100     width: 250     height: 150     visible: true      columnlayout {         anchors.fill: parent         spacing: 0         rowlayout {             spacing: 0             layout.preferredheight: 0.4*parent.height             layout.fillheight: false             rectangle {                 layout.fillheight: true                 layout.fillwidth: true                 color: "red"             }         }         rowlayout {             spacing: 0             layout.preferredheight: 0.2*parent.height             layout.fillheight: false             rectangle {                 layout.fillheight: true                 layout.fillwidth: true                 color: "darkgreen"             }             rectangle {                 layout.fillheight: true                 layout.preferredwidth: 0.8*parent.width                 color: "lightgreen"             }         }         rowlayout {             spacing: 0             layout.preferredheight: 0.4*parent.height             layout.fillheight: false             rectangle {                 layout.fillheight: true                 layout.fillwidth: true                 color: "darkblue"             }             rectangle {                 layout.fillheight: true                 layout.preferredwidth: 0.2*parent.width                 color: "blue"             }             rectangle {                 layout.fillheight: true                 layout.preferredwidth: 0.4*parent.width                 color: "lightblue"             }         }     } } 

update:

my approach seems more hacky expected:

  1. putting text elements children in layout raises binding loop warnings like:

qml qquicklayoutattached: binding loop detected property "preferredwidth"

if wrap text inside rectangle warnings disappear.

  1. the spacing: 0 seems play important role. omitting causes binding loop warnings.

while approach fluid layout design in qml works, has serious issue , might not fall under "best practices".

qtquick.layout not provide real improvements on classical anchoring system. recommand avoid them. can have way more control on layout using anchors.

here exact same design without qtquick.layout :

applicationwindow {     x: 500     y: 100     width: 250     height: 150     visible: true      column {         anchors.fill: parent          row {             anchors.left: parent.left             anchors.right: parent.right             height: 0.4 * parent.height              rectangle {                 anchors.top: parent.top                 anchors.bottom: parent.bottom                 width: parent.width                 color: "red"             }         }          row {             anchors.left: parent.left             anchors.right: parent.right             height: 0.2 * parent.height              rectangle {                 anchors.top: parent.top                 anchors.bottom: parent.bottom                 width: 0.2 * parent.width                 color: "darkgreen"             }              rectangle {                 anchors.top: parent.top                 anchors.bottom: parent.bottom                 width: 0.8 * parent.width                 color: "lightgreen"             }         }          row {             anchors.left: parent.left             anchors.right: parent.right             height: 0.4 * parent.height              rectangle {                 anchors.top: parent.top                 anchors.bottom: parent.bottom                 width: 0.4 * parent.width                 color: "darkblue"             }             rectangle {                 anchors.top: parent.top                 anchors.bottom: parent.bottom                 width: 0.2 * parent.width                 color: "blue"             }             rectangle {                 anchors.top: parent.top                 anchors.bottom: parent.bottom                 width: 0.4 * parent.width                 color: "lightblue"             }         }     } } 

so far never met design impossible without qtquick.layout.


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -