Results 1 to 2 of 2

Thread: Weird problem with QTableView::setResizeMode

  1. #1
    Join Date
    Sep 2009
    Posts
    15
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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?
    Attached Files Attached Files

  2. #2
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Weird problem with QTableView::setResizeMode

    You'll get the same results by setting the model after the setResizeMode() statements in DummyDialog. Try this:
    Qt Code:
    1. . . .
    2. myTable->horizontalHeader()->setResizeMode( 5, QHeaderView::Fixed );
    3.  
    4. TestCheckModel *aModel = new TestCheckModel( this );
    5. myTable->setModel( aModel );
    6.  
    7. qDebug() << "**************** After setResizeMode call **************************";
    8. . . .
    To copy to clipboard, switch view to plain text mode 
    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.

  3. The following 2 users say thank you to norobro for this useful post:

    rain87 (16th June 2010), winkle99 (29th June 2010)

Similar Threads

  1. weird problem in QGraphicsView / QGraphicsScene
    By Mrdata in forum Qt Programming
    Replies: 3
    Last Post: 24th November 2009, 19:26
  2. QFtp weird problem on windows
    By vcp in forum Qt Programming
    Replies: 0
    Last Post: 19th August 2009, 15:13
  3. setResizeMode for Splitter
    By ropel in forum Qt Programming
    Replies: 3
    Last Post: 1st July 2008, 08:56
  4. Replies: 1
    Last Post: 5th January 2008, 02:29
  5. Weird problem while porting from Qt3 to Qt4
    By vermarajeev in forum Qt Programming
    Replies: 4
    Last Post: 8th August 2007, 07:51

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.