[Qt-interest] QTableView with summary footer

Tony Rietwyk tony.rietwyk at rightsoft.com.au
Wed Sep 7 03:20:48 CEST 2011


> Sent: Wednesday, 7 September 2011 3:02 AM
> 
> Hi,
> 	i am trying to create a QTableView subclass that allows me to show a
> QHeaderView inside the viewport (above the horizontal scrollbar) with
> summary data of the columns of the model, but i am getting a difficult
time
> getting this to work, anyone have created something like this and can
point
> me in the correct direction please? Thanks.
> 
> Regards,
> Miguel Angel.

Hi Miguel, 

Instead of overriding QTableView,  I used a plain QWidget with two
QTableWidgets.  In my case, the columns fit within the window, so the
horizontal scroll bar is not an issue.  Have a look at
QAbstractScrollArea.setViewportMargins to get the summary between the
viewport and the scroll bar.  

Hope this helps, 

Tony.



In the contructor: 

	report = new QTableWidget( this );
	report->setObjectName( "ReportBody" );
	report->setSelectionMode( QAbstractItemView::SingleSelection );
	report->setSelectionBehavior( QAbstractItemView::SelectRows );
	report->setEditTriggers( QAbstractItemView::NoEditTriggers );
	report->verticalHeader()->setVisible( false );
	report->horizontalHeader()->setHighlightSections( false );
	report->horizontalHeader()->setClickable( false );
	report->horizontalHeader()->setMovable( false );

	summary = new QTableWidget( this );
	summary->setObjectName( "ReportSummary" );
	summary->setEditTriggers( QAbstractItemView::NoEditTriggers );
	summary->setFixedHeight( 20 );
	summary->setSizePolicy( QSizePolicy::MinimumExpanding,
QSizePolicy::Fixed );
	summary->verticalHeader()->setVisible( false );
	summary->horizontalHeader()->setHighlightSections( false );
	summary->horizontalHeader()->setClickable( false );
	summary->horizontalHeader()->setMovable( false );
	summary->horizontalHeader()->setResizeMode( QHeaderView::Fixed );

	connect( report->horizontalHeader(),
SIGNAL(sectionResized(int,int,int)), 
		SLOT(reportSectionResized(int,int,int)) );

	QVBoxLayout *lay = new QVBoxLayout();
	lay->addWidget( report, 1 );
	lay->addWidget( summary );
	lay->setSpacing( 0 );
	lay->setMargin( 0 );

	delete layout();
	setLayout( lay );

The slot just consists of: 

void ReportGrid::reportSectionResized(int logicalIndex,  int oldSize,  int
newSize)
{
	Q_UNUSED( oldSize );

	summary->horizontalHeader()->resizeSection( logicalIndex, newSize );
}





More information about the Qt-interest-old mailing list