|
|
On Wednesday 01 December 2004 13:16, Dutton, Sam wrote:
> I'm suggesting...
>
> 1. setShowToolTips(false) for the QListView
> 2. connect onItem(QListViewItem *) to a slot
> (showMyTooltip(QListViewItem*), for example) 3. in
> showMyTooltip(QListViewItem *item), get the QRect for item with
> QListView::itemRect(const QListViewItem*) 4. set a tooltip for the item
> QRect with QToolTip::tip(const QRect&, const QString&).
>
> Hope that's makes more sense.
Problem was not that I did not understand your suggestion, but that I to
reproduce the behaviour QListView has (only show tooltip for items not fully
shown), I needed access to private datastructures. Or so I thought. I fixed
it myself, by using the QToolTip subclass below. This way, the tooltip is
popped up in the same way it is done by default. I have reported the
behaviour as a bug to Trolltech by the way. Thanks for you help!
André
class QListViewToolTip : public QToolTip
{
public:
QListViewToolTip( QWidget *parent, QListView *lv );
void maybeTip( const QPoint &pos );
private:
QListView *view;
};
QListViewToolTip::QListViewToolTip( QWidget *parent, QListView *lv )
: QToolTip( parent ), view( lv )
{
}
void QListViewToolTip::maybeTip( const QPoint &pos )
{
if ( !parentWidget() || !view || !view->showToolTips() )
return;
QListViewItem *item = view->itemAt( pos );
QPoint contentsPos = view->viewportToContents( pos );
if ( !item || !item->columns )
return;
int col = view->header()->sectionAt( contentsPos.x() );
if ( view->header()->sectionSize( col ) >= item->width
( view->fontMetrics(), view, col ) )
return;
QRect r = view->itemRect( item );
int headerPos = view->header()->sectionPos( col );
r.setLeft( headerPos );
r.setRight( headerPos + view->header()->sectionSize( col ) );
tip( r, QStyleSheet::convertFromPlainText(item->text( col ) ));
//tip( r, item->text( col ) );
}
--
My opinions may have changed, but not the fact that I am right.
-- Ashleigh Brilliant
|
|