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. Integrating a custom layout with QML

Integrating a custom layout with QML

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 3 Posters 1.8k 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.
  • T Offline
    T Offline
    Tannz0rz
    wrote on last edited by Tannz0rz
    #1

    I've gone about creating my own layout that is a clone of WPF's XAML "Grid" class. The primary difference between Qt's and WPF's grid layout is the "star sizing" functionality, where each row and column is defined as a weighted proportion of the allotted space.

    The grid layout source can be found here: https://github.com/Tannz0rz/GridStarLayout

    For more information on star sizing, please refer to this Stack Overflow post: http://stackoverflow.com/questions/1768293/what-does-the-wpf-star-do-width-100

    It functions exactly as I'd hoped it would, however now I need to integrate it with QML to make app design extraordinarily simple. There are a few resources that show how to create your own QML component, such as Jeff Tranter's blog post, but I'm not sure how to handle all of the layout's nested children.

    I'm anticipating that the final QML layout will look like this:

    GridStarLayout {
        GridDefinition { // 2 rows, 3 columns
            RowDefinition { // 1 / (1 + 2) = 33% of height
                weight: 1.0
            }
            RowDefinition { // 2 / (1 + 2) = 66% of height
                weight: 2.0
            }
            ColumnDefinition { // 1 / (1 + 2 + 3) = 16.666% of width
                weight: 1.0
            }
            ColumnDefinition { // 2 / (1 + 2 + 3) = 33% of width
                weight: 2.0
            }
            ColumnDefinition { // 3 / (1 + 2 + 3) = 50% of width
                weight: 3.0
            }
        }
        Button {
            row: 0;
            column: 1;
            text: "Test"
        }
        Button {
            row: 1;
            column: 2;
            text: "Test"
        }
    }
    

    All suggestions and resource links would be greatly appreciated.

    Regards,
    Tannz0rz

    1 Reply Last reply
    0
    • T Offline
      T Offline
      t3685
      wrote on last edited by
      #2

      Have you looked at the source code of the standard QML layout element. They might be your best place to start.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        devel
        wrote on last edited by devel
        #3

        Looks like the 'Stretch Factors' of the old QWidget layouts.

        Also, in addition to looking at the source of the QML layouts, to better blend with QML, look at the example of how to implement 'attached properties' as like in 'Layout.preferredWidth'. To make the definition of the weights more compact or maybe stick it inside the elements.

        1 Reply Last reply
        0

        • Login

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