Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Loader will disturb the layout of the header of ApplicationWindow(QtQuick 2)
Forum Update on Monday, May 27th 2025

Loader will disturb the layout of the header of ApplicationWindow(QtQuick 2)

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 3 Posters 725 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • thamT Offline
    thamT Offline
    tham
    wrote on last edited by
    #1

    This is easier to explain by the example. Following codes work as expected

    main.qml

    import QtQuick 2.7
    import QtQuick.Controls 2.0
    import QtQuick.Layouts 1.0
    
    ApplicationWindow {
        visible: true
        width: 640
        height: 480        
    
        header: CustomToolBar{
    
        }
    }
    

    CustomToolBar.qml

    import QtQuick 2.6
    import QtQuick.Controls 2.0
    
    ToolBar {
        id : toolBar
    
        /*Loader{
            id: loader
        }//*/
    
        Row{
            spacing: 20
            anchors.fill: parent
    
            ToolButton {
                contentItem: Image {
                    fillMode: Image.PreserveAspectFit
                    horizontalAlignment: Image.AlignHCenter
                    verticalAlignment: Image.AlignVCenter
                    source: "qrc:/icons/settings.svg"
                    sourceSize.width: 40
                    width: sourceSize.width
                }            
            }
        }
    }
    

    Without the loader, the result looks good, the icon is within the Toolbar.

    no loader

    If I enable the loader, the icon will offset a little bit, this make the view looks bad

    has loader

    How could I fix this issue?Thanks

    R 1 Reply Last reply
    0
    • thamT tham

      This is easier to explain by the example. Following codes work as expected

      main.qml

      import QtQuick 2.7
      import QtQuick.Controls 2.0
      import QtQuick.Layouts 1.0
      
      ApplicationWindow {
          visible: true
          width: 640
          height: 480        
      
          header: CustomToolBar{
      
          }
      }
      

      CustomToolBar.qml

      import QtQuick 2.6
      import QtQuick.Controls 2.0
      
      ToolBar {
          id : toolBar
      
          /*Loader{
              id: loader
          }//*/
      
          Row{
              spacing: 20
              anchors.fill: parent
      
              ToolButton {
                  contentItem: Image {
                      fillMode: Image.PreserveAspectFit
                      horizontalAlignment: Image.AlignHCenter
                      verticalAlignment: Image.AlignVCenter
                      source: "qrc:/icons/settings.svg"
                      sourceSize.width: 40
                      width: sourceSize.width
                  }            
              }
          }
      }
      

      Without the loader, the result looks good, the icon is within the Toolbar.

      no loader

      If I enable the loader, the icon will offset a little bit, this make the view looks bad

      has loader

      How could I fix this issue?Thanks

      R Offline
      R Offline
      Roumed
      wrote on last edited by Roumed
      #2

      @tham if i'm not mistaking, the height of the header becomes smaller.
      This is about using the only element to make layout of the header.
      Try to set header height equals to row containing your toolbuttons explicitly.

      1 Reply Last reply
      1
      • jpnurmiJ Offline
        jpnurmiJ Offline
        jpnurmi
        wrote on last edited by jpnurmi
        #3

        A quote the docs:

        If only a single item is used within the ToolBar, it will resize to fit the implicit size of its contained item.
        

        If you add multiple children into ToolBar, it can no longer use the implicit size of the content, and falls back to the default height.

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved