Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 5

Qt-interest Archive, February 2008
QTableView row height


Message 1 in thread

When using QTableView, the rows of the corresponding table (even in case
when corresponding model contains simple one-line strings only for table
cells, and is set to be read-only) are way too big.  I've tried number of
solutions to this issue, including various resize mode settings for table
view vertical header, but to no avail.  If I replace using able view widget
with using tree view widget (of course, with corresponding minimal changes
in my model class), then "rows" are of the "right" size.  Now, while it is
not hard to further adapt tree view widget to fake table view widget, I'm
wondering is there any other solution to force table view widget to minimize
its rows height?  I've searched through the archive of this list, and found
couple references to the same issue, but no definite solution...

Thanks.

Message 2 in thread

Sagrailo wrote:

> I'm
> wondering is there any other solution to force table view widget to
> minimize its rows height?

I was successful in minimizing the row height this way:

MyTableView::MyTableView(...)
{
   const int rowHeight = fontMetrics().height() + 2;
   verticalHeader()->setDefaultSectionSize(rowHeight);

   verticalHeader()->setStyleSheet(
     "QHeaderView::section {"
        "padding-bottom: 0px;"
        "padding-top: 0px;"
        "padding-left: 0px;"
        "padding-right: 1px;"
        "margin: 0px;"
     "}"
   );
}

I also needed to reimplement:

void MyViewDelegate::drawDisplay(QPainter* painter, 
    const QStyleOptionViewItem& option, const QRect& rect, 
    const QString& text) const
{
   QRect r(rect.x(), rect.y(), rect.width(), rect.height() + 1);
   QItemDelegate::drawDisplay(painter, option, r, text);
}

It's a couple of weeks ago, that I wrote this code and unfortunately there
were several other bugs/limitations to work around, that I might have
forgotten something above. Let me know, when it doesn't work for you and I
will try to dig deeper in my code.

In our application I could display ~30% more rows and displaying as much
information as possible is the most important thing our customers are
interested in. 

HTH,
Uwe


--
 [ signature omitted ] 

Message 3 in thread

Do QTableView::resizeColumnsToContents() and  
QTableView::resizeRowsToContents() fit your needs?

On Wed, 27 Feb 2008 18:53:35 +0300, Sagrailo <sagrailo@xxxxxxxxx> wrote:
> When using QTableView, the rows of the corresponding table (even in case
> when corresponding model contains simple one-line strings only for table
> cells, and is set to be read-only) are way too big.  I've tried number of
> solutions to this issue, including various resize mode settings for table
> view vertical header, but to no avail.  If I replace using able view  
> widget
> with using tree view widget (of course, with corresponding minimal  
> changes
> in my model class), then "rows" are of the "right" size.  Now, while it  
> is
> not hard to further adapt tree view widget to fake table view widget, I'm
> wondering is there any other solution to force table view widget to  
> minimize
> its rows height?  I've searched through the archive of this list, and  
> found
> couple references to the same issue, but no definite solution...
>
> Thanks.

-- 
 [ signature omitted ]