Results 1 to 2 of 2

Thread: Dynamic Sizing of QTableView Column Widths

  1. #1
    Join Date
    Jun 2008
    Qt products

    Default Dynamic Sizing of QTableView Column Widths


    I have a QTableView in my applications main window, and need to set its column widths to a certain % of the window size and it needs to be done when the application first opens, the window opens maximized.

    So in my constructor I do this,

    Qt Code:
    1. // Initial queue column width %s
    2. QDesktopWidget* desk = QApplication::desktop();
    3. int width = desk->geometry().width() - 20; // - overheads
    4. ui->tbQueueView->horizontalHeader()->resizeSection(0, (width / 100) * 64);
    5. ui->tbQueueView->horizontalHeader()->resizeSection(1, (width / 100) * 7);
    6. ui->tbQueueView->horizontalHeader()->resizeSection(2, (width / 100) * 15);
    7. ui->tbQueueView->horizontalHeader()->resizeSection(3, (width / 100) * 5);
    8. ui->tbQueueView->horizontalHeader()->resizeSection(4, (width / 100) * 9);
    To copy to clipboard, switch view to plain text mode 

    This works, but If I have dual monitors it obviously doesn't because its greater than the size of a maximized application window.

    Is there a better approach? Ideally I would know the actual window size here and do %s of that, but because the window hasn't been drawn in the constructor I don't think I can find that out? Additionally I don't think there's a signal that I can use as soon as the window is drawn.

    Anyone know a good approach?


  2. #2
    Join Date
    Aug 2008
    Ukraine, Krivoy Rog
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    MacOS X Unix/X11 Windows

    Default Re: Dynamic Sizing of QTableView Column Widths

    you need to process QResizeEvent of a widget which contains a table view and do caluculation for a header again.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

Similar Threads

  1. QTableView column trouble
    By nategoofs in forum Qt Programming
    Replies: 6
    Last Post: 27th October 2009, 21:14
  2. QTreeView Fixed column & QTableView
    By jpujolf in forum Qt Programming
    Replies: 4
    Last Post: 13th August 2008, 10:35
  3. QTableView + QSqlQueryModel column alignment
    By frido in forum Qt Programming
    Replies: 1
    Last Post: 22nd July 2008, 07:12
  4. Currently sorted column in QTableView
    By borges in forum Newbie
    Replies: 1
    Last Post: 21st September 2007, 17:52
  5. QTableView without the first counter column?
    By pmaktieh.sirhc in forum Qt Programming
    Replies: 2
    Last Post: 4th January 2007, 23:03


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.