{
Q_OBJECT
public:
explicit MyTreeWidget
( QWidget *parent
= 0 );
...
protected slots:
void onSectionResized ( int column, int oldSize, int newSize );
...
};
class MyTreeWidget : public QTreeWidget
{
Q_OBJECT
public:
explicit MyTreeWidget( QWidget *parent = 0 );
...
protected slots:
void onSectionResized ( int column, int oldSize, int newSize );
...
};
To copy to clipboard, switch view to plain text mode
{
// reconnect the QHeaderView signal sectionResized to be managed by our class
disconnect( headerView, SIGNAL(sectionResized(int,int,int)) );
connect( headerView, SIGNAL(sectionResized(int,int,int)), SLOT(onSectionResized(int,int,int)) );
...
}
void MyTreeWidget::onSectionResized ( int column, int oldSize, int newSize )
{
// Set the first column width fixed
if( column <= 1 )
{
if( columnWidth( 0 ) != indentation() * 2 )
setColumnWidth( 0, indentation() * 2 );
}
else
QTreeWidget::columnResized( column, oldSize, newSize
);
}
MyTreeWidget::MyTreeWidget( QWidget *parent ) : QTreeWidget( parent )
{
// reconnect the QHeaderView signal sectionResized to be managed by our class
QHeaderView headerView = header();
disconnect( headerView, SIGNAL(sectionResized(int,int,int)) );
connect( headerView, SIGNAL(sectionResized(int,int,int)), SLOT(onSectionResized(int,int,int)) );
...
}
void MyTreeWidget::onSectionResized ( int column, int oldSize, int newSize )
{
// Set the first column width fixed
if( column <= 1 )
{
if( columnWidth( 0 ) != indentation() * 2 )
setColumnWidth( 0, indentation() * 2 );
}
else
QTreeWidget::columnResized( column, oldSize, newSize );
}
To copy to clipboard, switch view to plain text mode
Bookmarks