Qt-interest Archive, January 2007
setting default size of rows in QTableWidget
Message 1 in thread
I've tried a few different approaches and have come to the conclusion
that creating a row, and then resizing it with setRowHeight() will not
work, no matter how much it should work, based on replies I've received
and my own searches. I saw some disappointing replies here.
http://lists.trolltech.com/qt4-preview-feedback/2005-05/thread00691-0.html
Setting aside that this seems like a somewhat useless member function
(maybe I'm missing something), what are my options? I continually read
in messages, parse them, and then display them in the subclassed
QTableWidget, always in row 0 (and subsequently pushing the others
down). There can be thousands of rows by the end of the day which leads
me to believe resizing them regularly will waste resources. Is there an
easy way to set the default size each row will be when it's created, and
I won't have to worry about it?
currently, I'm doing this when I get a new message
tbl->insertRow( 0 ); // insert row
tbl->resizeRowToContents( 0 ); // make visible
cout << "row 0 height: " << tbl_trades->rowHeight( 0 ) << endl;
Column height is always 25. At qtcentre, I was told to reimplement
sizeHintForRow(). I tried this, but to no avail.
Seems this is never called.
int myview::sizeHintForRow( int row ) const
{
cout << "sizeHintForRow" << row << endl;
return 20;
}
Any help is greatly appreciated.
--
[ signature omitted ]
Message 2 in thread
Paul England wrote:
> I've tried a few different approaches and have come to the conclusion
> that creating a row, and then resizing it with setRowHeight() will not
> work, no matter how much it should work, based on replies I've received
> and my own searches. I saw some disappointing replies here.
>
> http://lists.trolltech.com/qt4-preview-feedback/2005-05/thread00691-0.html
>
> Setting aside that this seems like a somewhat useless member function
> (maybe I'm missing something), what are my options? I continually read
> in messages, parse them, and then display them in the subclassed
> QTableWidget, always in row 0 (and subsequently pushing the others
> down). There can be thousands of rows by the end of the day which leads
> me to believe resizing them regularly will waste resources. Is there an
> easy way to set the default size each row will be when it's created, and
> I won't have to worry about it?
>
> currently, I'm doing this when I get a new message
>
> tbl->insertRow( 0 ); // insert row
> tbl->resizeRowToContents( 0 ); // make visible
> cout << "row 0 height: " << tbl_trades->rowHeight( 0 ) << endl;
>
> Column height is always 25. At qtcentre, I was told to reimplement
> sizeHintForRow(). I tried this, but to no avail.
> Seems this is never called.
>
> int myview::sizeHintForRow( int row ) const
> {
> cout << "sizeHintForRow" << row << endl;
> return 20;
> }
>
> Any help is greatly appreciated.
Hi Paul. What worked for me was to implement an item delegate with a
custom #sizeHint method returning the desired height. To force the
delegate's size hint on the view, I had to call the view's
#resizeRowsToContents method. To reflect model changes, I also connected
the models's #rowsInserted and #rowsRemoved signals with the view's
#resizeRowsToContents slot.
I'm sure there is a simpler solution though, so I'd be interested in
other approaches as well :)
hth
M
--
[ signature omitted ]
Message 3 in thread
Martin:
Thanks. I've seen similar approaches. Truth be told, I'm not familiar
at all with this delagate model/view stuff, although I need to be. I
guess I should use this as my excuse. I'm still not hot about calling
something that resizes the entire sheet everytime a new row is added.
I'll be adding several rows every few seconds.
Cheers
Paul
Martin wrote:
> Paul England wrote:
>
>> I've tried a few different approaches and have come to the conclusion
>> that creating a row, and then resizing it with setRowHeight() will not
>> work, no matter how much it should work, based on replies I've received
>> and my own searches. I saw some disappointing replies here.
>>
>> http://lists.trolltech.com/qt4-preview-feedback/2005-05/thread00691-0.html
>>
>> Setting aside that this seems like a somewhat useless member function
>> (maybe I'm missing something), what are my options? I continually read
>> in messages, parse them, and then display them in the subclassed
>> QTableWidget, always in row 0 (and subsequently pushing the others
>> down). There can be thousands of rows by the end of the day which leads
>> me to believe resizing them regularly will waste resources. Is there an
>> easy way to set the default size each row will be when it's created, and
>> I won't have to worry about it?
>>
>> currently, I'm doing this when I get a new message
>>
>> tbl->insertRow( 0 ); // insert row
>> tbl->resizeRowToContents( 0 ); // make visible
>> cout << "row 0 height: " << tbl_trades->rowHeight( 0 ) << endl;
>>
>> Column height is always 25. At qtcentre, I was told to reimplement
>> sizeHintForRow(). I tried this, but to no avail.
>> Seems this is never called.
>>
>> int myview::sizeHintForRow( int row ) const
>> {
>> cout << "sizeHintForRow" << row << endl;
>> return 20;
>> }
>>
>> Any help is greatly appreciated.
>>
>
>
> Hi Paul. What worked for me was to implement an item delegate with a
> custom #sizeHint method returning the desired height. To force the
> delegate's size hint on the view, I had to call the view's
> #resizeRowsToContents method. To reflect model changes, I also connected
> the models's #rowsInserted and #rowsRemoved signals with the view's
> #resizeRowsToContents slot.
>
> I'm sure there is a simpler solution though, so I'd be interested in
> other approaches as well :)
>
>
> hth
> M
>
> --
> 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 4 in thread
One approach that works, and only has to be done once, is:
tbl->verticalHeader()->setDefaultSectionSize(fontMetrics().lineSpacing
() + 5)
On Jan 23, 2007, at 7:21 PM, Paul England wrote:
> Martin:
>
> Thanks. I've seen similar approaches. Truth be told, I'm not
> familiar at all with this delagate model/view stuff, although I
> need to be. I guess I should use this as my excuse. I'm still
> not hot about calling something that resizes the entire sheet
> everytime a new row is added. I'll be adding several rows every
> few seconds.
>
> Cheers
> Paul
>
> Martin wrote:
>> Paul England wrote:
>>
>>> I've tried a few different approaches and have come to the
>>> conclusion
>>> that creating a row, and then resizing it with setRowHeight()
>>> will not
>>> work, no matter how much it should work, based on replies I've
>>> received
>>> and my own searches. I saw some disappointing replies here.
>>>
>>> http://lists.trolltech.com/qt4-preview-feedback/2005-05/
>>> thread00691-0.html
>>>
>>> Setting aside that this seems like a somewhat useless member
>>> function
>>> (maybe I'm missing something), what are my options? I
>>> continually read
>>> in messages, parse them, and then display them in the subclassed
>>> QTableWidget, always in row 0 (and subsequently pushing the others
>>> down). There can be thousands of rows by the end of the day
>>> which leads
>>> me to believe resizing them regularly will waste resources. Is
>>> there an
>>> easy way to set the default size each row will be when it's
>>> created, and
>>> I won't have to worry about it?
>>>
>>> currently, I'm doing this when I get a new message
>>>
>>> tbl->insertRow( 0 ); // insert row
>>> tbl->resizeRowToContents( 0 ); // make visible
>>> cout << "row 0 height: " << tbl_trades->rowHeight( 0 ) << endl;
>>>
>>> Column height is always 25. At qtcentre, I was told to reimplement
>>> sizeHintForRow(). I tried this, but to no avail.
>>> Seems this is never called.
>>>
>>> int myview::sizeHintForRow( int row ) const
>>> {
>>> cout << "sizeHintForRow" << row << endl;
>>> return 20;
>>> }
>>>
>>> Any help is greatly appreciated.
>>>
>>
>>
>> Hi Paul. What worked for me was to implement an item delegate with a
>> custom #sizeHint method returning the desired height. To force the
>> delegate's size hint on the view, I had to call the view's
>> #resizeRowsToContents method. To reflect model changes, I also
>> connected
>> the models's #rowsInserted and #rowsRemoved signals with the view's
>> #resizeRowsToContents slot.
>>
>> I'm sure there is a simpler solution though, so I'd be interested in
>> other approaches as well :)
>>
>>
>> hth
>> M
>>
>> --
>> 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/
>>
>>
>
> --
> 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 5 in thread
Michael Rice wrote:
> One approach that works, and only has to be done once, is:
>
> tbl->verticalHeader()->setDefaultSectionSize(fontMetrics().lineSpacing()
> + 5)
Wow. Afterwards, it seems like I should have come up with this myself.
So easy, and so well working... thanks a lot :)
M
> On Jan 23, 2007, at 7:21 PM, Paul England wrote:
>
>> Martin:
>>
>> Thanks. I've seen similar approaches. Truth be told, I'm not
>> familiar at all with this delagate model/view stuff, although I need
>> to be. I guess I should use this as my excuse. I'm still not hot
>> about calling something that resizes the entire sheet everytime a new
>> row is added. I'll be adding several rows every few seconds.
>>
>> Cheers
>> Paul
>>
>> Martin wrote:
>>> Paul England wrote:
>>>
>>>> I've tried a few different approaches and have come to the conclusion
>>>> that creating a row, and then resizing it with setRowHeight() will not
>>>> work, no matter how much it should work, based on replies I've received
>>>> and my own searches. I saw some disappointing replies here.
>>>>
>>>> http://lists.trolltech.com/qt4-preview-feedback/2005-05/thread00691-0.html
>>>>
>>>>
>>>> Setting aside that this seems like a somewhat useless member function
>>>> (maybe I'm missing something), what are my options? I continually read
>>>> in messages, parse them, and then display them in the subclassed
>>>> QTableWidget, always in row 0 (and subsequently pushing the others
>>>> down). There can be thousands of rows by the end of the day which
>>>> leads
>>>> me to believe resizing them regularly will waste resources. Is
>>>> there an
>>>> easy way to set the default size each row will be when it's created,
>>>> and
>>>> I won't have to worry about it?
>>>>
>>>> currently, I'm doing this when I get a new message
>>>>
>>>> tbl->insertRow( 0 ); // insert row
>>>> tbl->resizeRowToContents( 0 ); // make visible
>>>> cout << "row 0 height: " << tbl_trades->rowHeight( 0 ) << endl;
>>>>
>>>> Column height is always 25. At qtcentre, I was told to reimplement
>>>> sizeHintForRow(). I tried this, but to no avail.
>>>> Seems this is never called.
>>>>
>>>> int myview::sizeHintForRow( int row ) const
>>>> {
>>>> cout << "sizeHintForRow" << row << endl;
>>>> return 20;
>>>> }
>>>>
>>>> Any help is greatly appreciated.
>>>>
>>>
>>>
>>> Hi Paul. What worked for me was to implement an item delegate with a
>>> custom #sizeHint method returning the desired height. To force the
>>> delegate's size hint on the view, I had to call the view's
>>> #resizeRowsToContents method. To reflect model changes, I also connected
>>> the models's #rowsInserted and #rowsRemoved signals with the view's
>>> #resizeRowsToContents slot.
>>>
>>> I'm sure there is a simpler solution though, so I'd be interested in
>>> other approaches as well :)
>>>
>>>
>>> hth
>>> M
>>>
>>> --
>>> 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/
>>>
>>>
>>
>> --
>> 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/
>>
>>
>
> --
> 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 ]