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. StackView and ObjectModel width problem
QtWS25 Last Chance

StackView and ObjectModel width problem

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 3 Posters 977 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.
  • LunoL Offline
    LunoL Offline
    Luno
    wrote on last edited by
    #1

    Hi!
    I'm working on my project in QML and I've meet a problem. I need to make a ListView (menu), where I can select the element, click on it and see the details on the separate view. I've used the stocqt example as a solution for this issue, but I've meet a problem with width of StackView element: if width of the RForm (id:RView) is set, the application isn't running (it's trying to start without any success). So, now I have:
    main.qml

    
    ApplicationWindow {
        id:mainWindow
    width:1280
    height:720
    StackView {
        id:homeView
        anchors.fill: parent
        initialItem: DataList {
        }
        }
    

    DataList.qml:

    import QtQuick 2.4
    import QtQuick.Controls 2.0
    import QtQuick.Layouts 1.0
    import QtQuick.Controls.Material 2.0
    import QtQml.Models 2.1
    import "."
    
    Rectangle {
        id:mainView
        width:mainWindows.width
        height:parent.height
        property alias currentIndex: root.currentIndex
        ListView {
            id:root
            width:mainWindow.width
            height:parent.height
            anchors.fill: parent
            snapMode: ListView.SnapOneItem
            highlightRangeMode: ListView.StrictlyEnforceRange
            highlightMoveDuration: 250
            focus: false
            orientation: ListView.Horizontal
            boundsBehavior: Flickable.StopAtBounds
            FormModelForm {
                id: dataModel
                dataId: listView.currentDataId
            }
            model: ObjectModel {
                DListView {
                    id:listView
                    anchors.fill: parent
                    width:root.width
                    height:root.height
                }
                RForm {
                    id:RView
                    dataSet:RDataModel
                    width:root.width
                    height:root.height
    
                }
            }
        }
    }
    
    

    I really need to use StackView, because I have a MasterFlow menu. Could you help me how to set the width property of this element? May be there is an another idea how to realise such ListView?

    E 1 Reply Last reply
    0
    • LunoL Luno

      Hi!
      I'm working on my project in QML and I've meet a problem. I need to make a ListView (menu), where I can select the element, click on it and see the details on the separate view. I've used the stocqt example as a solution for this issue, but I've meet a problem with width of StackView element: if width of the RForm (id:RView) is set, the application isn't running (it's trying to start without any success). So, now I have:
      main.qml

      
      ApplicationWindow {
          id:mainWindow
      width:1280
      height:720
      StackView {
          id:homeView
          anchors.fill: parent
          initialItem: DataList {
          }
          }
      

      DataList.qml:

      import QtQuick 2.4
      import QtQuick.Controls 2.0
      import QtQuick.Layouts 1.0
      import QtQuick.Controls.Material 2.0
      import QtQml.Models 2.1
      import "."
      
      Rectangle {
          id:mainView
          width:mainWindows.width
          height:parent.height
          property alias currentIndex: root.currentIndex
          ListView {
              id:root
              width:mainWindow.width
              height:parent.height
              anchors.fill: parent
              snapMode: ListView.SnapOneItem
              highlightRangeMode: ListView.StrictlyEnforceRange
              highlightMoveDuration: 250
              focus: false
              orientation: ListView.Horizontal
              boundsBehavior: Flickable.StopAtBounds
              FormModelForm {
                  id: dataModel
                  dataId: listView.currentDataId
              }
              model: ObjectModel {
                  DListView {
                      id:listView
                      anchors.fill: parent
                      width:root.width
                      height:root.height
                  }
                  RForm {
                      id:RView
                      dataSet:RDataModel
                      width:root.width
                      height:root.height
      
                  }
              }
          }
      }
      
      

      I really need to use StackView, because I have a MasterFlow menu. Could you help me how to set the width property of this element? May be there is an another idea how to realise such ListView?

      E Offline
      E Offline
      Eeli K
      wrote on last edited by
      #2

      @Luno First,

      id:mainView
      width:mainWindows.width
      

      mainWindows doesn't exist (should be mainWindow?)
      Second,

      id:RView
      dataSet:RDataModel
      

      Only type names should begin with upper case letter.
      Third, the implicit/explicit sizing system of Quick is annoying. In most cases you have to find a working combination of implicitWidth and width properties for your components.

      1 Reply Last reply
      0
      • LunoL Offline
        LunoL Offline
        Luno
        wrote on last edited by
        #3

        Thank you for your reply. I'm sorry, I've changed some ids, but it's ok in the code. Originally (in stocqt), all components of ObjectModel are in the Rectangle (but I have to you StackView because of MasterFlow menu). So, I think that all problems are in differences between these objects.. I'll try to work with implicitWidth, may be it's a solution

        ekkescornerE 1 Reply Last reply
        0
        • LunoL Luno

          Thank you for your reply. I'm sorry, I've changed some ids, but it's ok in the code. Originally (in stocqt), all components of ObjectModel are in the Rectangle (but I have to you StackView because of MasterFlow menu). So, I think that all problems are in differences between these objects.. I'll try to work with implicitWidth, may be it's a solution

          ekkescornerE Offline
          ekkescornerE Offline
          ekkescorner
          Qt Champions 2016
          wrote on last edited by
          #4

          @Luno you're using QtQuickControls2 StackView - please try QQC2 Page instead of a Rectangle

          ekke ... Qt Champion 2016 | 2024 ... mobile business apps
          5.15 --> 6.8 https://t1p.de/ekkeChecklist
          QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

          LunoL 1 Reply Last reply
          0
          • ekkescornerE ekkescorner

            @Luno you're using QtQuickControls2 StackView - please try QQC2 Page instead of a Rectangle

            LunoL Offline
            LunoL Offline
            Luno
            wrote on last edited by Luno
            #5

            Unfortunately, it'n't a solution:(
            But I'm stupid...the "root" element should has the following properties

                    Layout.fillHeight: true
                    Layout.fillWidth: true
            

            Thank you everyone, who tried to help with it :)

            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