[Qt-interest] QTableView with summary footer
Linos
info at linos.es
Wed Sep 7 08:59:52 CEST 2011
El 07/09/11 03:20, Tony Rietwyk escribió:
>
>> 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 );
> }
>
This was going to be my next try so know that would work well helps me, thanks Tony.
It is somewhat impressive for me how difficult it is to add a footer to a table
in Qt, it seems to be designed against this common feature.
Regards,
Miguel Angel.
More information about the Qt-interest-old
mailing list