Can we have checkbox in Header of QTreeView along with Sorting symbol
-
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 -
Hi @qtEnthusiast ,
Seems this works for you.
https://forum.qt.io/topic/12626/how-to-add-check-box-inside-qtree-widget/3Keep tracking the the QtreeView for the whether the checkbox is checked or not. you can find here.
http://stackoverflow.com/questions/8175122/qtreeview-checkboxes -
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
-
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
@Qt-Enthusiast
you can reimplementQHeaderView
and you can make use ofQMultiComboBox
like this .
http://qt-apps.org/content/show.php/QMultiComboBox?content=149416 -
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();
}
-
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
-
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
@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 ); }