1 Attachment(s)
Weird problem with QTableView::setResizeMode
I am trying to create an in-house, generic open dialog that uses different data models depending on what the user needs to open. I ran into a really weird problem that I'm not sure is me or if there's a bug in Qt. (I'm attaching a simple test case.)
My initial approach was to make the a generic (so that there's no need to subclass from it.) You just set a different model and a few flags and off you go. The problem I ran into is that depending on when I call setResizeMode it does not affect the columns.
My test app puts up a dialog window with a button in it (InitButtonDialog). When the button is clicked a second dialog (DummyDialog) is displayed with a table in it. That table has six columns. The desire is for column 0 to stretch and the others be fixed. The dialog writes, via qDebug() the results of a call to QHeaderView::resizeMode before QHeaderView::setResizeMode is called and after it is called.
If I make the QTableView::setModel call *within* DummyDialog everything works as expected. The resize modes are set and the columns are displayed as desired. ( The qDebug() output reflects this.) HOWEVER, if I make the setModel call fin (InitButtonDialog), the reset modes are not set ( the qDebug() output reflects this as well.)
Has anyone ever seen this?
Re: Weird problem with QTableView::setResizeMode
You'll get the same results by setting the model after the setResizeMode() statements in DummyDialog. Try this:
Code:
. . .
myTable->horizontalHeader
()->setResizeMode
( 5,
QHeaderView::Fixed );
TestCheckModel *aModel = new TestCheckModel( this );
myTable->setModel( aModel );
qDebug() << "**************** After setResizeMode call **************************";
. . .
As you'll see, when you set the model it resets a column's resize mode to "0". Also evidenced by the columns being adjustable.
I put in a setStretchLastSection(true) statement and it worked no matter when the model was set. I'm not sure of the reasoning behind having stretchLastSection() survive the setting of a new model and resizeMode() not. Looks like either all settings would translate to the new model or none would.
Take a look at the sources, there might be a clue there. I will if I get a minute. Or maybe one of the gurus around here will clue us in.