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. GridView and ObjectModel. Highlight size and resize of dynamically added elements.
Forum Updated to NodeBB v4.3 + New Features

GridView and ObjectModel. Highlight size and resize of dynamically added elements.

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 293 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.
  • B Offline
    B Offline
    bronstein87
    wrote on 23 Mar 2020, 17:06 last edited by
    #1

    Hi. I have three questions about GridView and ObjectModel.
    Here is a little example to explain my problems:

    main.qml

    import QtQuick 2.12
    import QtQuick.Window 2.12
    import QtQuick.Controls 2.12
    import QtQml.Models 2.12
    import QtQuick.Layouts 1.12
    
    
    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
        Page
        {
            width: parent.width
            height: parent.height
            footer: Button{
                width: parent.width
                height:  100
                text: "test"
                function createObject()
                {
    
                    var component = Qt.createComponent("CameraPreview.qml");
                    if (component.status == Component.Ready)
                    {
                        var newObject = component.createObject(om, {"width" : test.cellWidth - 10, 
    "height" : test.cellHeight - 10});
                        om.append(newObject)
                    }
                }
                onClicked: createObject()
            }
            Pane
            {
                anchors.top: parent.top + 100
                width: parent.width
                height: parent.height
                id: syncTab
                GridView {
                    id: test
                    anchors.fill: parent
                    cellWidth: width / 4
                    cellHeight: height / 3
                    highlight: Rectangle { width : test.cellWidth; height: test.cellHeight; 
    color: "lightsteelblue"; radius: 5; }
                    focus: true
                    model: ObjectModel {
                        id: om
                        CameraPreview {width : test.cellWidth - 30
                            height : test.cellHeight - 30 }
                        CameraPreview {width : 10
                            height : 10 }
    
                    }
                }
    
            }
        }
    }
    

    and CameraPreview.qml

    import QtQuick 2.0
    
    Rectangle
    {
        color: "black"
        opacity: 0.3
    }
    

    First question: Why is highlight size is same as element size? I set highlight rectangle size as :

    width : test.cellWidth; height: test.cellHeight;
    

    and first element size is:

    width : test.cellWidth - 30 height : test.cellHeight - 30
    

    but highlight covers just element area, not all cell area

    Second question:
    Why dynamically added objects don't resize when i resize GridView?

    var newObject = component.createObject(om, {"width" : test.cellWidth - 10, 
    "height" : test.cellHeight - 10});
    

    here new element size depends on GridView size, but it doesn't work when i resize window.

    And my last question is how to change currentIndex by mouse click?

    1 Reply Last reply
    0

    1/1

    23 Mar 2020, 17:06

    • Login

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