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. Can we have checkbox in Header of QTreeView along with Sorting symbol
QtWS25 Last Chance

Can we have checkbox in Header of QTreeView along with Sorting symbol

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 4.2k 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.
  • Q Offline
    Q Offline
    Qt Enthusiast
    wrote on last edited by Qt Enthusiast
    #1

    Hi All
    Can we have a checkbox in Header of QTreeView along with Sorting symbox . When I click on checkbox , then I should be able to perform some actions

    1 Reply Last reply
    0
    • Ni.SumiN Offline
      Ni.SumiN Offline
      Ni.Sumi
      wrote on last edited by Ni.Sumi
      #2

      Hi @qtEnthusiast ,

      Seems this works for you.
      https://forum.qt.io/topic/12626/how-to-add-check-box-inside-qtree-widget/3

      Keep tracking the the QtreeView for the whether the checkbox is checked or not. you can find here.
      http://stackoverflow.com/questions/8175122/qtreeview-checkboxes

      1 Reply Last reply
      1
      • Q Offline
        Q Offline
        Qt Enthusiast
        wrote on last edited by
        #3

        As I understand it for each item in QtreeWidget . I am asking on common check box for header label in QtreeView it is different . LIke we have sorting mark in QtreeView like that

        RatzzR 1 Reply Last reply
        0
        • Q Qt Enthusiast

          As I understand it for each item in QtreeWidget . I am asking on common check box for header label in QtreeView it is different . LIke we have sorting mark in QtreeView like that

          RatzzR Offline
          RatzzR Offline
          Ratzz
          wrote on last edited by
          #4

          @Qt-Enthusiast
          you can reimplement QHeaderView and you can make use of QMultiComboBox like this .
          http://qt-apps.org/content/show.php/QMultiComboBox?content=149416

          --Alles ist gut.

          1 Reply Last reply
          1
          • Q Offline
            Q Offline
            Qt Enthusiast
            wrote on last edited by Qt Enthusiast
            #5

            I could not make out for example (As I was not able to access the example code). if some one can elaborate on how implement checkbox in header of QTreeView/ I have following code using QTreeView

            #include <QApplication>
            #include <QSplitter>
            #include <QTreeView>
            #include <QListView>
            #include <QTableView>
            #include <QStandardItemModel>

            int main( int argc, char **argv ) {

            QApplication app( argc, argv );
            QTreeView *tree = new QTreeView();
            QListView *list = new QListView();
            QTableView *table = new QTableView();
            QSplitter splitter;
            splitter.addWidget( tree );
            splitter.addWidget( list );
            splitter.addWidget( table );
            QStandardItemModel model( 5, 2 );

            for( int r=0; r<5; r++ )
            for( int c=0; c<2; c++) {
            QStandardItem *item = new QStandardItem( QString("Row:%0, Column:%1").arg(r).arg(c) );
            if( c == 0 )
            for( int i=0; i<3; i++ ) {
            QStandardItem *child = new QStandardItem( QString("Item %0").arg(i) );
            child->setEditable( false );
            item->appendRow( child );
            }
            model.setItem(r, c, item);
            }

            model.setHorizontalHeaderItem( 0, new QStandardItem( "Foo" ) );
            model.setHorizontalHeaderItem( 1, new QStandardItem( "Bar-Baz" ) );
            tree->setModel( &model );
            list->setModel( &model );
            table->setModel( &model );
            list->setSelectionModel( tree->selectionModel() );
            table->setSelectionModel( tree->selectionModel() );
            table->setSelectionBehavior( QAbstractItemView::SelectRows );
            table->setSelectionMode( QAbstractItemView::SingleSelection );
            splitter.show();
            return app.exec();
            

            }

            1 Reply Last reply
            0
            • Q Offline
              Q Offline
              Qt Enthusiast
              wrote on last edited by
              #6

              I tried the example here in the link

              https://wiki.qt.io/Qt_project_org_faq#How_can_I_insert_a_checkbox_into_the_header_of_my_view.3F

              But I could not get how to connect slot on click/unclick of the check box . Can some one quide for the that . or its there any alternative way to implement check box in the header

              mrjjM 1 Reply Last reply
              1
              • Q Qt Enthusiast

                I tried the example here in the link

                https://wiki.qt.io/Qt_project_org_faq#How_can_I_insert_a_checkbox_into_the_header_of_my_view.3F

                But I could not get how to connect slot on click/unclick of the check box . Can some one quide for the that . or its there any alternative way to implement check box in the header

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by mrjj
                #7

                @Qt-Enthusiast
                Hi that sample does not use a real checkbox so there is no signal.
                but you can easy make your own signal for it.

                class MyHeader : public QHeaderView
                {
                public:
                ....
                protected:
                  void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const ....
                 signals: ///
                 void CheckedChanged( bool state); /// define signal
                  }
                  void mousePressEvent(QMouseEvent *event)
                  {
                ..... ...... ...
                  // emit ur new signal
                  emit CheckedChanged( isOn );
                  }
                
                1 Reply Last reply
                2

                • Login

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