Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to connect QStandardItem checkbox to a slot
Qt 6.11 is out! See what's new in the release blog

How to connect QStandardItem checkbox to a slot

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 794 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.
  • ivanicyI Offline
    ivanicyI Offline
    ivanicy
    wrote on last edited by
    #1

    Hello!!

    I have an application with a QTreeView. This QTreeView has QStandardItems and I have put a checkbox in them with the setCheckable() property. How can I connect this checkbox with a slot?

    Thank you very much!

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      Requires Qt >= 5.11

      connect(model,&QAbstractItemModel::dataChanged,[](const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles){
          if(!roles.isEmpty() && !roles.contains(Qt::CheckStateRole))
              return;
          for(int i=topLeft.row();i<=bottomRight.row();++i){
              for(int j=topLeft.column();j<=bottomRight.column();++j){
                  qDebug() << "CheckBox Changed: Item data" <<  topLeft.model()->index(i,j,topLeft.parent()).data();
              }
          }
      });
      

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      ivanicyI 1 Reply Last reply
      3
      • VRoninV VRonin

        Requires Qt >= 5.11

        connect(model,&QAbstractItemModel::dataChanged,[](const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles){
            if(!roles.isEmpty() && !roles.contains(Qt::CheckStateRole))
                return;
            for(int i=topLeft.row();i<=bottomRight.row();++i){
                for(int j=topLeft.column();j<=bottomRight.column();++j){
                    qDebug() << "CheckBox Changed: Item data" <<  topLeft.model()->index(i,j,topLeft.parent()).data();
                }
            }
        });
        
        ivanicyI Offline
        ivanicyI Offline
        ivanicy
        wrote on last edited by
        #3

        @VRonin Thank you very much!!! That's that I need!!

        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