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

Qt-interest Archive, June 2007
How to set the most top-left corner of a QTableWidget?


Message 1 in thread

Hi All,

I am using QTableWidget which has both horizontal and vertical header 
labels.

setHorizontalHeaderLabels(hHeaders);
setVerticalHeaderLabels(vHeaders);

The most top-left corner in the view is empty.
Can I put there something, for example, a title, or
a better way: how can I draw a diagonal line which separates two names 
of headers?

Thanks in advance,
Lingfa


--
 [ signature omitted ] 

Message 2 in thread

There is no easy way to do this. you can use QObject::findChild() to get
a pointer to it.

This has been answered before on this list:
http://lists.trolltech.com/qt-interest/2007-04/thread00998-0.html

Cheers,
Peter

> The most top-left corner in the view is empty.
> Can I put there something, for example, a title, or
> a better way: how can I draw a diagonal line which separates two names
> of headers?
> 
> Thanks in advance,
> Lingfa

--
 [ signature omitted ] 

Message 3 in thread

Peter Prade wrote:

>There is no easy way to do this. you can use QObject::findChild() to get
>a pointer to it.
>
>This has been answered before on this list:
>http://lists.trolltech.com/qt-interest/2007-04/thread00998-0.html
>
>Cheers,
>Peter
>  
>
Peter, 

Thank you for your help. 
I read the link. A solution seems in an attached main.cpp file, which I cannot see, even I do register in.

QWidget *corner = tableWidget->cornerWidget(); // return NULL!
tableWidget->setCornerWidget(new QPushButton("Me")); 
// goes to the right-bottom corner when there are two scroll bars,
// which is not an expected location !
corner = tableWidget->cornerWidget(); // yes it is.

More idea?

Thanks
Lingfa


--
 [ signature omitted ] 

Message 4 in thread

cornerWidget() is *NOT* the correct widget. it comes from
QAbstractScrollArea and means an entirely different area (the one in the
corner when you have 2 scrollbars).

Until now, there is no easy method to get the corner widget of a
tableWidget (which is a button with custom drawing!), afaik the only
chance you have is to use QObject::findChild() - it should be the only
child that is a button, so you can retrieve it with:
QAbstractButton* cornerButton =
tableWidget->findChild<QAbstractButton*>();

i don't think you can set a text on it though, as it seems it has a
custom paint	event. J-P Nurmi showed how to do it in the main.cpp
that you mentioned. (i had no problems getting it after i registered.
maybe you have to flush the browser cache?)

Basically what you need to do (besides setting a text) is to install an
eventFilter on the cornerButton and handle QEvent::Paint so that text is
shown.

Cheers,
Peter

> -----Original Message-----
> From: Lingfa Yang [mailto:lingfa@xxxxxxx]
> Sent: Monday, June 25, 2007 10:07 PM
> To: qt-interest@xxxxxxxxxxxxx
> Cc: Qt Interest
> Subject: Re: How to set the most top-left corner of a QTableWidget?
> 
> Peter Prade wrote:
> 
> >There is no easy way to do this. you can use QObject::findChild() to
get
> >a pointer to it.
> >
> >This has been answered before on this list:
> >http://lists.trolltech.com/qt-interest/2007-04/thread00998-0.html
> >
> >Cheers,
> >Peter
> >
> >
> Peter,
> 
> Thank you for your help.
> I read the link. A solution seems in an attached main.cpp file, which
I
> cannot see, even I do register in.
> 
> QWidget *corner = tableWidget->cornerWidget(); // return NULL!
> tableWidget->setCornerWidget(new QPushButton("Me"));
> // goes to the right-bottom corner when there are two scroll bars,
> // which is not an expected location !
> corner = tableWidget->cornerWidget(); // yes it is.
> 
> More idea?
> 
> Thanks
> Lingfa

--
 [ signature omitted ] 

Message 5 in thread

Peter Prade wrote:

>cornerWidget() is *NOT* the correct widget. it comes from
>QAbstractScrollArea and means an entirely different area (the one in the
>corner when you have 2 scrollbars).
>
>Until now, there is no easy method to get the corner widget of a
>tableWidget (which is a button with custom drawing!), afaik the only
>chance you have is to use QObject::findChild() - it should be the only
>child that is a button, so you can retrieve it with:
>QAbstractButton* cornerButton =
>tableWidget->findChild<QAbstractButton*>();
>
>i don't think you can set a text on it though, as it seems it has a
>custom paint	event. J-P Nurmi showed how to do it in the main.cpp
>that you mentioned. (i had no problems getting it after i registered.
>maybe you have to flush the browser cache?)
>
>Basically what you need to do (besides setting a text) is to install an
>eventFilter on the cornerButton and handle QEvent::Paint so that text is
>shown.
>
>Cheers,
>Peter
>
Peter,

After activating my account, I am able to see the code you mentioned, 
where an eventFilter was installed. It works prefect for me.

Now I can set a title:

QAbstractButton* cornerButton = this->findChild<QAbstractButton*>();
cornerButton->setText(title);

Also, I can deal with button click for extension:

connect(cornerButton, SIGNAL(clicked()), SLOT(cornerClicked()));

Thank you so much.
Lingfa


--
 [ signature omitted ]