Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

why does the anchors.fill Unfill GroupBox in QML?



  • the follow Screenshots link.
    link text

    QQuickWidget* p = new QQuickWidget();
    QUrl source("qrc:/qml/groupbox.qml");
    p->setResizeMode(QQuickWidget::SizeRootObjectToView);
    p->setSource(source);
    
    import QtQuick 2.8
    import QtQuick.Controls 2.1
    import QtQuick.Layouts 1.2
    
    GroupBox{
            id:mainBox
            property string imagePath:"qrc:/resources/border.png"
            GridLayout{
                   anchors.centerIn:parent
                   anchors.fill:parent
                   rows:100
                   columns:100
                   columnSpacing:0
                   rowSpacing:0
                   GroupBox{
                         anchors.centerIn:parent
                         anchors.fill:parent    
                         BorderImage{
                                  id:bImage
                                  anchors.centerIn:parent
                                  anchors.fill:parent             
                                  source:imagePath
                        }               
                         Layout.column:0
                         Layout.row:0
                         Layout.columnSpan:100
                         Layout.rowSpan:100
                         Layout.margins:0                                   
                   }             
           }
    }
    


  • hi

    @mirro said in why does the anchors.fill Unfill GroupBox in QML?:

    GridLayout{
    anchors.centerIn:parent
    anchors.fill:parent
    rows:100
    columns:100
    columnSpacing:0
    rowSpacing:0
    GroupBox{
    anchors.centerIn:parent // << can't use anchors here
    anchors.fill:parent //<<

    I am not sure this is the main issue but you can not use anchors inside an item that is managed by QML Layout, it leads to undefined behavior, use Layout.alignment instead

    note : when you say anchors.fill parent you don't need anchors.centerIn:parent because anchors.fill actually fills and centers in the parent


Log in to reply