Results 1 to 3 of 3

Thread: QTableView empty space or too little space.

  1. #1
    Join Date
    Dec 2007
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QTableView empty space or too little space.

    I've got a QTableView containing a QStandardItemModel which gives a table of 2 columns, 4 rows, with both horizontal and vertical headers on each (so a 3x5 grid). I've put this QTableView inside a QGroupBox which is part of the main QGridLayout.

    I'd like the table to appear with all the cells with no scrollbars and no blank space, but I can't achieve it. I'm managed to remove the blank space down the right-hand side using table->horizontalHeader()->setResizeMode(QHeaderView::Stretch), but can't find an equivalent to remove the vertical scroll bar and/or the empty space at the bottom.

    Here's a snippet of the code:
    Qt Code:
    1. QGroupBox *Window::SetLineTableLayout()
    2. {
    3. line_model = new QStandardItemModel(4, 2, this);
    4. line_model->setHeaderData(0, Qt::Horizontal, tr("Start"));
    5. line_model->setHeaderData(1, Qt::Horizontal, tr("End"));
    6. line_model->setHeaderData(0, Qt::Vertical, tr("Index"));
    7. line_model->setHeaderData(1, Qt::Vertical, tr("X"));
    8. line_model->setHeaderData(2, Qt::Vertical, tr("Y"));
    9. line_model->setHeaderData(3, Qt::Vertical, tr("Z"));
    10. // line_model has values placed in it elsewhere.
    11.  
    12. QTableView *table = new QTableView;
    13.  
    14. table->setModel(line_model);
    15.  
    16. QItemSelectionModel *selectionModel = new QItemSelectionModel(line_model);
    17. table->setSelectionModel(selectionModel);
    18. table->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
    19.  
    20. QGroupBox *line_box = new QGroupBox(tr("Selected Line"));
    21. QVBoxLayout *layout = new QVBoxLayout();
    22. layout->addWidget(table);
    23. line_box->setLayout(layout);
    24.  
    25. return line_box;
    26. }
    To copy to clipboard, switch view to plain text mode 

    which is called from (editted version):
    Qt Code:
    1. QGridLayout *mainLayout = new QGridLayout;
    2.  
    3. QGroupBox *line_box = new QGroupBox;
    4. line_box = SetLineTableLayout();
    5.  
    6. mainLayout->addWidget(line_box, 1, 1, 1, 1);
    7. // Lots of other widgets added to the grid not shown here for clarity.
    8.  
    9. setLayout(mainLayout);
    To copy to clipboard, switch view to plain text mode 

    Any clues will be welcome.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QTableView empty space or too little space.

    what about setHorizontalScrollBarPolicy () (and vertical)?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Dec 2007
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTableView empty space or too little space.

    No, that doesn't seem to work. I can remove the scroll bar using it, but it doesn't enlarge the box to allow the table to fit in. It just shows the first couple of rows without a scroll bar.

Similar Threads

  1. empty space in QGridLayout
    By eleanor in forum Qt Programming
    Replies: 1
    Last Post: 4th July 2008, 10:36
  2. Ensure columns in qtableview uses all available space
    By oysteinpettersen in forum Qt Programming
    Replies: 2
    Last Post: 10th January 2008, 12:28
  3. QTableView showing empty fields
    By ederbs in forum Qt Programming
    Replies: 5
    Last Post: 4th October 2007, 01:30
  4. linking user space and kernel space programs with qmake
    By zielchri in forum Qt Programming
    Replies: 9
    Last Post: 9th March 2006, 00:11
  5. QTableWidget click in empty space results in error?
    By Giel Peters in forum Qt Programming
    Replies: 4
    Last Post: 21st January 2006, 01:07

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.