Qt-interest Archive, June 2007
How to set a precise size of QTableWidget to prevent from having scroll bars?
Message 1 in thread
Hi All,
I’m working on QTableWidget, which may or may not have scroll bars.
If my table is in a reasonable size (not too wide, not too tall) I wish
to set a precise size which does not leave extra space in the viewport,
and on the other hand, not having scroll bars show up. What is the
precise size?
I tried:
adjustSize();
and
resizeRowsToContents();
esizeColumnsToContents();
and
resize(size());
or check and resize() base on
QSize size = this->sizeHint();
QSize baseSize = this->baseSize();
None of them works.
By the way, I do not change any size policy, or set any size hint
explicitly, and my table has no delegates.
Thanks
Lingfa
--
[ signature omitted ]
Message 2 in thread
El Miércoles, 27 de Junio de 2007 18:13, Lingfa Yang escribió:
> Hi All,
>
> I’m working on QTableWidget, which may or may not have scroll bars.
>
> If my table is in a reasonable size (not too wide, not too tall) I wish
> to set a precise size which does not leave extra space in the viewport,
> and on the other hand, not having scroll bars show up. What is the
> precise size?
>
> I tried:
> adjustSize();
> and
> resizeRowsToContents();
> esizeColumnsToContents();
> and
> resize(size());
> or check and resize() base on
> QSize size = this->sizeHint();
> QSize baseSize = this->baseSize();
> None of them works.
>
> By the way, I do not change any size policy, or set any size hint
> explicitly, and my table has no delegates.
>
Try with:
setColumnWidth()
setRowHeight()
setFixedWidth()
setFixedHeight()
If you want some column to stretch, you can try:
horizontalHeader()->setStretchLastSection(true);
horizontalHeader()->setResizeMode(0, QHeaderView::Stretch); // column 0
--
[ signature omitted ]
Message 3 in thread
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Those techniques didn't work well for me. A similar question came up
earlier this month. See <a
href="http://lists.trolltech.com/qt-interest/2007-06/msg00887.html#msg00887">http://lists.trolltech.com/qt-interest/2007-06/msg00887.html#msg00887</a><br>
<br>
<br>
Manuel Parrilla wrote:
<blockquote cite="mid:200706271851.40472.mparrilla@xxxxxxx" type="cite">
<pre wrap="">El Miércoles, 27 de Junio de 2007 18:13, Lingfa Yang escribió:
</pre>
<blockquote type="cite">
<pre wrap="">Hi All,
I’m working on QTableWidget, which may or may not have scroll bars.
If my table is in a reasonable size (not too wide, not too tall) I wish
to set a precise size which does not leave extra space in the viewport,
and on the other hand, not having scroll bars show up. What is the
precise size?
I tried:
adjustSize();
and
resizeRowsToContents();
esizeColumnsToContents();
and
resize(size());
or check and resize() base on
QSize size = this->sizeHint();
QSize baseSize = this->baseSize();
None of them works.
By the way, I do not change any size policy, or set any size hint
explicitly, and my table has no delegates.
</pre>
</blockquote>
<pre wrap=""><!---->Try with:
setColumnWidth()
setRowHeight()
setFixedWidth()
setFixedHeight()
If you want some column to stretch, you can try:
horizontalHeader()->setStretchLastSection(true);
horizontalHeader()->setResizeMode(0, QHeaderView::Stretch); // column 0
</pre>
</blockquote>
</body>
</html>
--
[ signature omitted ]
Message 4 in thread
Susan Macchia wrote:
> Those techniques didn't work well for me. A similar question came up
> earlier this month. See
> http://lists.trolltech.com/qt-interest/2007-06/msg00887.html#msg00887
>
Hi Susan,
Yes. it is the question, where I saw your way to calculate the width:
columnWidth() is ok, but verticalHeader()->width() does not work after
setVerticalHeaderLabels().
verticalHeader()->width() return 15 if rowCount<10 even through I have
a much longer string in the vertical header which takes 200 pixels.
Do you have more idea?
Thanks,
Lingfa
--
[ signature omitted ]
Message 5 in thread
Are you calling ::resizeColumnToContents first?
Rather than setVerticalHeaderLabels, I have a QTableView derivation that
is implementing the ::headerData method. Perhaps you can convert to a
TableView-Model-Delegate?
Lingfa Yang wrote:
> Susan Macchia wrote:
>
>> Those techniques didn't work well for me. A similar question came up
>> earlier this month. See
>> http://lists.trolltech.com/qt-interest/2007-06/msg00887.html#msg00887
>>
> Hi Susan,
>
> Yes. it is the question, where I saw your way to calculate the width:
> columnWidth() is ok, but verticalHeader()->width() does not work after
> setVerticalHeaderLabels().
>
> verticalHeader()->width() return 15 if rowCount<10 even through I
> have a much longer string in the vertical header which takes 200 pixels.
>
> Do you have more idea?
>
> Thanks,
> Lingfa
>
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
--
[ signature omitted ]
Message 6 in thread
Susan Macchia wrote:
> Are you calling ::resizeColumnToContents first?
>
Call it or not both works fine if I does not setVerticalHeaderLabels.
> Rather than setVerticalHeaderLabels, I have a QTableView derivation
> that is implementing the ::headerData method. Perhaps you can convert
> to a TableView-Model-Delegate?
>
I finally find the trick: after setVerticalHeaderLabels() if I add
tableWidget->resize(1,1); // It can be any size.
then, verticalHeader()->width() returns a correct value, and a precise
size of tableWidget can be calculated.
Problem solved!
Thanks for your help.
Lingfa
--
[ signature omitted ]
Message 7 in thread
> I finally find the trick: after setVerticalHeaderLabels() if I add
>
> tableWidget->resize(1,1); // It can be any size.
>
> then, verticalHeader()->width() returns a correct value, and a precise
> size of tableWidget can be calculated.
An expert points to me that problem comes from size is not calculated
after setVerticalHeaderLabels().
A way to solve it is hide-and-show like this:
int before = verticalHeader()->width(); // not correct!
hide(); show(); // hide-and-show to trigger size calculation
int after = verticalHeader()->width(); // it is correct now!
Lingfa
--
[ signature omitted ]
Message 8 in thread
This looks "kludgey" to me (IMHO), though I'm sure it works. Is there
another way to tell the widget to perform size calculation.
Lingfa Yang wrote:
>
>> I finally find the trick: after setVerticalHeaderLabels() if I add
>>
>> tableWidget->resize(1,1); // It can be any size.
>>
>> then, verticalHeader()->width() returns a correct value, and a
>> precise size of tableWidget can be calculated.
>
> An expert points to me that problem comes from size is not calculated
> after setVerticalHeaderLabels().
> A way to solve it is hide-and-show like this:
>
> int before = verticalHeader()->width(); // not correct!
> hide(); show(); // hide-and-show to trigger size calculation
> int after = verticalHeader()->width(); // it is correct now!
---
This communication contains confidential information. If you are not the intended recipient please return this email to the sender and delete it from your records.
Diese Nachricht enthält vertrauliche Informationen. Sollten Sie nicht der beabsichtigte Empfänger dieser E-mail sein, senden Sie bitte diese an den Absender zurück und löschen Sie die E-mail aus Ihrem System.
--
[ signature omitted ]