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

Qt-interest Archive, December 2007
How does QTableWidget work


Message 1 in thread

Hello all,

I'm currently having loads of bugs in my program due to my lack of
understand on how table in Qt4 works and the documentation doesn't
help.
Let me tell you what I think I know so that you can confirm or correct me.

QTableWidget has rows and columns starting at 0 and goint to
rowCount()-1 and columnCount()-1.
Each cell in the beginning is empty and to add something to it you
have to instantiate a new QTableItem and set the cell with setItem to
contain the item.
When you delete a row, with removeRow, you're removing a specific row
and all the others remain untouched. So if you have 10 rows (0 to 10)
and you delete row 0, you end up with row 1 to 9.
When you delete the row, it'll free all QTableItems on that row and
delete the row itself. However, doing clearContents will only delete
the items and not the row.

Is this ok so far?

Cheers,

-- 
 [ signature omitted ] 

Message 2 in thread

On Monday 10 December 2007 17:58:17 Paulo J. Matos wrote:
> Hello all,
>
> I'm currently having loads of bugs in my program due to my lack of
> understand on how table in Qt4 works and the documentation doesn't
> help.
> Let me tell you what I think I know so that you can confirm or correct me.
>
> QTableWidget has rows and columns starting at 0 and goint to
> rowCount()-1 and columnCount()-1.
> Each cell in the beginning is empty and to add something to it you
> have to instantiate a new QTableItem and set the cell with setItem to
> contain the item.
> When you delete a row, with removeRow, you're removing a specific row
> and all the others remain untouched. So if you have 10 rows (0 to 10)
> and you delete row 0, you end up with row 1 to 9.
> When you delete the row, it'll free all QTableItems on that row and
> delete the row itself. However, doing clearContents will only delete
> the items and not the row.
>
> Is this ok so far?
>
> Cheers,

Check out the setCellWidget function which is quite nice.
You can add your own QCheckBox or QLineEdit (and add for example the password 
style to it) and connect slots to those specific cells. 

Happy coding,
Eric

--
 [ signature omitted ] 

Message 3 in thread

On Dec 10, 2007 10:16 PM, Eric Methorst <arnalon@xxxxxxxxx> wrote:
> On Monday 10 December 2007 17:58:17 Paulo J. Matos wrote:
> > Hello all,
> >
> > I'm currently having loads of bugs in my program due to my lack of
> > understand on how table in Qt4 works and the documentation doesn't
> > help.
> > Let me tell you what I think I know so that you can confirm or correct me.
> >
> > QTableWidget has rows and columns starting at 0 and goint to
> > rowCount()-1 and columnCount()-1.
> > Each cell in the beginning is empty and to add something to it you
> > have to instantiate a new QTableItem and set the cell with setItem to
> > contain the item.
> > When you delete a row, with removeRow, you're removing a specific row
> > and all the others remain untouched. So if you have 10 rows (0 to 10)
> > and you delete row 0, you end up with row 1 to 9.
> > When you delete the row, it'll free all QTableItems on that row and
> > delete the row itself. However, doing clearContents will only delete
> > the items and not the row.
> >
> > Is this ok so far?
> >
> > Cheers,
>
> Check out the setCellWidget function which is quite nice.
> You can add your own QCheckBox or QLineEdit (and add for example the password
> style to it) and connect slots to those specific cells.
>

Thanks for the tip. Using this method instead of messing around with
TableItems, solved most my problems... :-D Yay
BTW, do you have any tip on how to make the horizontal of the
headerview of a table have the same width as the table itself?

Cheers,

Paulo Matos

> Happy coding,
> Eric
>
> --
> 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

On Monday 10 December 2007 23:47:33 Paulo J. Matos wrote:
<SNIP/>
> > Check out the setCellWidget function which is quite nice.
> > You can add your own QCheckBox or QLineEdit (and add for example the
> > password style to it) and connect slots to those specific cells.
>
> Thanks for the tip. Using this method instead of messing around with
> TableItems, solved most my problems... :-D Yay
> BTW, do you have any tip on how to make the horizontal of the
> headerview of a table have the same width as the table itself?
>
> Cheers,
>
> Paulo Matos
>

Nope, sorry.
Been looking for that one myself too.
So far, the only option I can see is to derive from QTableWidget, overrule the 
resizeEvent function and resize your column in there.

Maybe there's a better trick, but I haven't found it yet.

Happy coding,
Eric

--
 [ signature omitted ] 

Message 5 in thread

Eric Methorst wrote:
> On Monday 10 December 2007 23:47:33 Paulo J. Matos wrote:
> <SNIP/>
>   
>>> Check out the setCellWidget function which is quite nice.
>>> You can add your own QCheckBox or QLineEdit (and add for example the
>>> password style to it) and connect slots to those specific cells.
>>>       
>> Thanks for the tip. Using this method instead of messing around with
>> TableItems, solved most my problems... :-D Yay
>> BTW, do you have any tip on how to make the horizontal of the
>> headerview of a table have the same width as the table itself?
>>
>> Cheers,
>>
>> Paulo Matos
>>
>>     
>
> Nope, sorry.
> Been looking for that one myself too.
> So far, the only option I can see is to derive from QTableWidget, overrule the 
> resizeEvent function and resize your column in there.
>
> Maybe there's a better trick, but I haven't found it yet.
>
>   

It is far easier to make the last column fill out the extra space:

table->horizontalHeader()->setStretchLastSection(true);

--Justin


begin:vcard
begin:vcard
fn:Justin Noel
n:Noel;Justin
org:ICS;Engineering
adr:;;54B Middlesex Trpk.;Bedford;MA;01730;USA
email;internet:justin@xxxxxxx
title:Sr. Consulting Engineer / Certified Qt Instructor
tel;work:617-621-0060
x-mozilla-html:FALSE
url:www.ics.com
version:2.1
end:vcard


Message 6 in thread

On Dec 11, 2007 12:57 AM, Justin Noel <justin@xxxxxxx> wrote:
> Eric Methorst wrote:
> > On Monday 10 December 2007 23:47:33 Paulo J. Matos wrote:
> > <SNIP/>
> >
> >>> Check out the setCellWidget function which is quite nice.
> >>> You can add your own QCheckBox or QLineEdit (and add for example the
> >>> password style to it) and connect slots to those specific cells.
> >>>
> >> Thanks for the tip. Using this method instead of messing around with
> >> TableItems, solved most my problems... :-D Yay
> >> BTW, do you have any tip on how to make the horizontal of the
> >> headerview of a table have the same width as the table itself?
> >>
> >> Cheers,
> >>
> >> Paulo Matos
> >>
> >>
> >
> > Nope, sorry.
> > Been looking for that one myself too.
> > So far, the only option I can see is to derive from QTableWidget, overrule the
> > resizeEvent function and resize your column in there.
> >
> > Maybe there's a better trick, but I haven't found it yet.
> >
> >
>
> It is far easier to make the last column fill out the extra space:
>
> table->horizontalHeader()->setStretchLastSection(true);
>

That's interesting but still, only useful if width headers is smaller
than width of table, otherwise, I end up with a horizontal scrollbar,
which I don't like.
I would like the user to manage the table with the space it has for
the table without messing with the horizontal scrollbar. This means
basically setting the sum of the width of the sections to the table
width and disallowing the resize of the last section (or something
like this).

> --Justin
>
>
>
>
>



-- 
 [ signature omitted ] 

Message 7 in thread

On Tuesday 11 December 2007 01:57:34 Justin Noel wrote:
> Eric Methorst wrote:
> > On Monday 10 December 2007 23:47:33 Paulo J. Matos wrote:
> > <SNIP/>
> >
> >>> Check out the setCellWidget function which is quite nice.
> >>> You can add your own QCheckBox or QLineEdit (and add for example the
> >>> password style to it) and connect slots to those specific cells.
> >>
> >> Thanks for the tip. Using this method instead of messing around with
> >> TableItems, solved most my problems... :-D Yay
> >> BTW, do you have any tip on how to make the horizontal of the
> >> headerview of a table have the same width as the table itself?
> >>
> >> Cheers,
> >>
> >> Paulo Matos
> >
> > Nope, sorry.
> > Been looking for that one myself too.
> > So far, the only option I can see is to derive from QTableWidget,
> > overrule the resizeEvent function and resize your column in there.
> >
> > Maybe there's a better trick, but I haven't found it yet.
>
> It is far easier to make the last column fill out the extra space:
>
> table->horizontalHeader()->setStretchLastSection(true);
>
> --Justin
Ah, thanks. 
That was exactly what I'd been looking for.
Misssed the bit where QTableQWidget was derived from QTableView :(

Happy coding,
Eric

--
 [ signature omitted ]