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. How do I access items created by a DelegateChoice inside a TableView?
Forum Updated to NodeBB v4.3 + New Features

How do I access items created by a DelegateChoice inside a TableView?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 2 Posters 718 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.
  • K Offline
    K Offline
    Kyle Hall
    wrote on last edited by
    #1

    I've spent countless hours trying to figure this out. I have an app that release print jobs for printing. Each job has a pages to print, copies to print, and cost per page. The user selects a printer and the cost in the table is updated from that calculation. If the user doesn't have enough funds to print to the printer, I want to disable the "Print" button. It seems simple enough but I've tried dozens of techniques, not of which have worked.

    The simple solution seems to be to get that Button, and set its enabled value to false. However, I can't access that element by its id, so it must be out of scope.

    Here is the ComboBox for printer selection: https://github.com/Libki/libki-print-station/blob/printer_selection/PrintRelease.qml#L142

    Here is the Button that needs disabled: https://github.com/Libki/libki-print-station/blob/printer_selection/PrintRelease.qml#L223

    Is there any way to get access to that button from the comboboxes onActivated method?

    J.HilkJ 1 Reply Last reply
    0
    • K Kyle Hall

      I've spent countless hours trying to figure this out. I have an app that release print jobs for printing. Each job has a pages to print, copies to print, and cost per page. The user selects a printer and the cost in the table is updated from that calculation. If the user doesn't have enough funds to print to the printer, I want to disable the "Print" button. It seems simple enough but I've tried dozens of techniques, not of which have worked.

      The simple solution seems to be to get that Button, and set its enabled value to false. However, I can't access that element by its id, so it must be out of scope.

      Here is the ComboBox for printer selection: https://github.com/Libki/libki-print-station/blob/printer_selection/PrintRelease.qml#L142

      Here is the Button that needs disabled: https://github.com/Libki/libki-print-station/blob/printer_selection/PrintRelease.qml#L223

      Is there any way to get access to that button from the comboboxes onActivated method?

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @Kyle-Hall if you really need to iterate over all the contentItem you can do that:

      TableView{
              id:tableView
              anchors.fill: parent
              Component.onCompleted:{
                  for(var child in tableView.contentItem.children) {
                      console.log(tableView.contentItem.children[child].text)
                  }
              }
      
                  model: 50
              delegate: Label{
                  text: modelData
              }
          }
      

      But I would probably go with a proper c++ model and do my logic there.


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      1
      • K Offline
        K Offline
        Kyle Hall
        wrote on last edited by
        #3

        Thanks! I curious about the your last statement. This is my first QML application, can you point me to any documentation for creating C++ model to use in a QML app?

        Thanks again!

        J.HilkJ 1 Reply Last reply
        0
        • K Kyle Hall

          Thanks! I curious about the your last statement. This is my first QML application, can you point me to any documentation for creating C++ model to use in a QML app?

          Thanks again!

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by J.Hilk
          #4

          @Kyle-Hall sure, take a look here:

          https://doc.qt.io/qt-5/qtquick-modelviewsdata-cppmodels.html

          the interesting section is probably the one about QAbstractItemModel Subclass


          actually, for your tableview case, there exists an actual Qt Example:

          https://doc.qt.io/qt-5/qtquick-tableview-gameoflife-example.html


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          K 1 Reply Last reply
          0
          • J.HilkJ J.Hilk

            @Kyle-Hall sure, take a look here:

            https://doc.qt.io/qt-5/qtquick-modelviewsdata-cppmodels.html

            the interesting section is probably the one about QAbstractItemModel Subclass


            actually, for your tableview case, there exists an actual Qt Example:

            https://doc.qt.io/qt-5/qtquick-tableview-gameoflife-example.html

            K Offline
            K Offline
            Kyle Hall
            wrote on last edited by
            #5

            @J-Hilk thank you!

            I did end up finding an alternative solution. I created a signal on my TableView and wired it to each button. Then, when the ComboBox changes, I call a function on the TableView that fires the signal, triggering the print buttons to reevaluate if they should be enabled or not.

            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