Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

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

    General and Desktop
    4
    7
    3645
    Loading More Posts
    • 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
      Qt Enthusiast last edited by Qt Enthusiast

      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 Reply Quote 0
      • Ni.Sumi
        Ni.Sumi last edited by Ni.Sumi

        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 Reply Quote 1
        • Q
          Qt Enthusiast last edited by

          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

          Ratzz 1 Reply Last reply Reply Quote 0
          • Ratzz
            Ratzz @Qt Enthusiast last edited by

            @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 Reply Quote 1
            • Q
              Qt Enthusiast last edited by Qt Enthusiast

              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 Reply Quote 0
              • Q
                Qt Enthusiast last edited by

                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

                mrjj 1 Reply Last reply Reply Quote 1
                • mrjj
                  mrjj Lifetime Qt Champion @Qt Enthusiast last edited by mrjj

                  @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 Reply Quote 2
                  • First post
                    Last post