PDA

View Full Version : Update to 4.4.2: cornerWidget functionality changed



mclark
15th October 2008, 22:06
I've recently updated my Qt installation from 4.3.4 to 4.4.2.

I've been experimenting with Qt's Model/View code using QTableView. A sample app I've been using, when compiled under 4.4.2 behaves differently than when using 4.3.4. Clicking on the cornerWidget of the table's headerView selects all cells in the table as expected, but Ctrl-click does not deselect as it did in 4.3.4, in fact it appears to do nothing.

I'm not calling setSelectionMode() (although I have tried calling it using ExtendedSelection but this had no effect).

My use of QHeaderView is as follows:

// Set properties in the column headers
QHeaderView* m_pColHdrView = horizontalHeader();
m_pColHdrView->setHighlightSections( false );
m_pColHdrView->setMovable( false );
m_pColHdrView->setDefaultAlignment( Qt::AlignCenter );
m_pColHdrView->setSortIndicator( 1, Qt::DescendingOrder );
m_pColHdrView->setSortIndicatorShown( true );
m_pColHdrView->setStretchLastSection( false );

// Set properties in the row headers
QHeaderView* rowHdrView = verticalHeader();
rowHdrView->setMovable( false );
rowHdrView->setResizeMode( QHeaderView::Custom );
rowHdrView->setClickable( true );
I suspect, as has happened before when switching to a new version of Qt, that I have uncovered some defect in my code that just happened to work before. Any ideas about what may cause the cornerWidget of a QTableView or QTableWidget to behave differently in this situation?

mclark
28th October 2008, 20:07
I now believe this is a Qt 4.4.2 issue. A mouse press on the corner widget selects all items in both versions but Ctrl mouse press unselects all only in 4.3.4. The following code displays this problem:


#include <QApplication>
#include <QTableView>
#include <QStandardItemModel>

int main( int argc, char **argv )
{
QApplication app( argc, argv );

QTableView *table = new QTableView();

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) );

model.setItem(r, c, item);
}
}

table->setModel( &model );
table->show();

return app.exec();
}

mclark
20th November 2008, 23:09
I reported this as a bug to the Trolls but they said they won't fix it because it was an "intended behavior change".

That being the case, how is one supposed to unselect all?

Is there a way to ask them this directly?

wysota
20th November 2008, 23:22
Apply an event filter on the header and catch that mouse press so that you can handle it yourself if you need it.

mclark
20th November 2008, 23:32
Apply an event filter on the header and catch that mouse press so that you can handle it yourself if you need it.

If I trap the mouse press I'll use QTableWidget::clearSelection(), correct?

I guess I'm just lazy and want Qt to do it for me like they used to.;)

wysota
21st November 2008, 01:14
You can use whatever you want... QItemSelectionModel::clear() is a good candidate as well.