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

Qt-interest Archive, January 2007
QTreeView ToolTips on a Mac


Message 1 in thread

Hi,

I had an interesting phenomenon today that I wanted to share with you.
Maybe you can clarify this for me.

Ok. So I got a QTreeView and want tool tips on its items.  
Documentation says
(.../Qt-4.2.0/doc/html/widgets-tooltips.html) that I should re-implement
event(QEvent * mpEvent), which I did to the t:

	// Tooltip
	bool MyTreeView::event(QEvent * mpEvent)
	{
	    if (mpEvent -> type() != QEvent::ToolTip)
	    {
	        return QTreeView::event(mpEvent);
	    }
	
	    QHelpEvent * help = dynamic_cast < QHelpEvent * >(mpEvent);
	    QModelIndex index = indexAt(help -> pos());

	    qDebug() << index;
	
	    return  true;
	}


What I expected to see was the the index of the item below the mouse  
cursor being
dumped. But no such luck: The item _below_ the item under the mouse  
cursor is being
dumped! So I decided to look a little deeper into it, and I found out  
that help -> pos()
for some reason beyond me returns the wrong position. It does not  
take the header() into
account -- so I did:

	    QPoint mypos = help -> pos();
	    mypos.setY(mypos.y() - header() -> height());
	    QModelIndex index = indexAt(mypos);

This works just fine.

But please enlighten me:

a) Can you reproduce this behavior?
b) Is this expected behavior, ie. did I do something wrong? Or is it  
a bug?

QT Version is 4.2.0, and I'm on MacOS.

Thanks a lot in advance,

Shimaron

--
 [ signature omitted ] 

Message 2 in thread

I don't know about your specific problem, but QTreeView shouldn't  
have to be overridden to show tool tips.  Ideally, your model will  
provide an appropriate value for the Qt::ToolTipRole in the data()  
method.  This works as expected on OS X.

Jason


On Jan 23, 2007, at 1:19 PM, Shimaron Greywolf wrote:

> Hi,
>
> I had an interesting phenomenon today that I wanted to share with you.
> Maybe you can clarify this for me.
>
> Ok. So I got a QTreeView and want tool tips on its items.  
> Documentation says
> (.../Qt-4.2.0/doc/html/widgets-tooltips.html) that I should re- 
> implement
> event(QEvent * mpEvent), which I did to the t:
>
> 	// Tooltip
> 	bool MyTreeView::event(QEvent * mpEvent)
> 	{
> 	    if (mpEvent -> type() != QEvent::ToolTip)
> 	    {
> 	        return QTreeView::event(mpEvent);
> 	    }
> 	
> 	    QHelpEvent * help = dynamic_cast < QHelpEvent * >(mpEvent);
> 	    QModelIndex index = indexAt(help -> pos());
>
> 	    qDebug() << index;
> 	
> 	    return  true;
> 	}
>
>
> What I expected to see was the the index of the item below the  
> mouse cursor being
> dumped. But no such luck: The item _below_ the item under the mouse  
> cursor is being
> dumped! So I decided to look a little deeper into it, and I found  
> out that help -> pos()
> for some reason beyond me returns the wrong position. It does not  
> take the header() into
> account -- so I did:
>
> 	    QPoint mypos = help -> pos();
> 	    mypos.setY(mypos.y() - header() -> height());
> 	    QModelIndex index = indexAt(mypos);
>
> This works just fine.
>
> But please enlighten me:
>
> a) Can you reproduce this behavior?
> b) Is this expected behavior, ie. did I do something wrong? Or is  
> it a bug?
>
> QT Version is 4.2.0, and I'm on MacOS.
>
> Thanks a lot in advance,
>
> Shimaron
>
> --
> 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 3 in thread

Hi Jason,

that is a very good point! Did so, purrs like a kitten. I wonder why  
the aforementioned
Documentation does not point this out and in fact suggests re- 
implementing event()...

Anyway, this solves my problem. Thanks a bunch!

Shimaron

--
 [ signature omitted ]