#ifndef N_LIST_VIEW_TOOLTIP__H
#define N_LIST_VIEW_TOOLTIP__H
#include <qtooltip.h>
#include <qlistview.h>
#include <qguardedptr.h>
class n_list_view_tooltip
: public QToolTip{
private:
protected:
virtual void maybeTip( const QPoint& p );
public:
n_list_view_tooltip
( QListView * widget, QToolTipGroup
* group
= 0 );
~n_list_view_tooltip();
};//n_list_view_tooltip
#endif
#ifndef N_LIST_VIEW_TOOLTIP__H
#define N_LIST_VIEW_TOOLTIP__H
#include <qtooltip.h>
#include <qlistview.h>
#include <qguardedptr.h>
class n_list_view_tooltip: public QToolTip
{
private:
QGuardedPtr< QListView > f_list_view;
protected:
virtual void maybeTip( const QPoint& p );
public:
n_list_view_tooltip( QListView * widget, QToolTipGroup * group = 0 );
~n_list_view_tooltip();
QListView * list_view() const;
void set_list_view( QListView * value );
};//n_list_view_tooltip
#endif
To copy to clipboard, switch view to plain text mode
#include "n_list_view_tooltip.h"
#include <qheader.h>
n_list_view_tooltip
::n_list_view_tooltip( QListView * widget, QToolTipGroup
* group
): QToolTip( widget, group
), f_list_view
( widget
) {
}
n_list_view_tooltip::~ n_list_view_tooltip( )
{
if ( f_list_view )
remove( f_list_view );
}
QListView * n_list_view_tooltip
::list_view( ) const {
return f_list_view;
}
void n_list_view_tooltip
::set_list_view( QListView * value
) {
f_list_view = value;
}
void n_list_view_tooltip
::maybeTip( const QPoint & p
) {
if ( !f_list_view )
{
qDebug( "void n_list_view_tooltip::maybeTip( %d, %d ): f_list_view is NULL", p.x(), p.y() );
return;
}
if ( ! f_list_view->viewport()->rect().contains( p ) )
{
qDebug( "void n_list_view_tooltip::maybeTip( %d, %d ): viewport does not contain p!", p.x(), p.y() );
return;
}
QPoint point
( f_list_view
->viewport
()->mapFromParent
( p
) );
QListViewItem * item = f_list_view->itemAt( point );
if ( !item )
{
qDebug( "void n_list_view_tooltip::maybeTip( %d, %d ): item is NULL", p.x(), p.y() );
return;
}
QString s
= item
->text
( f_list_view
->header
()->sectionAt
( point.
x() ) );
QRect r
( f_list_view
->itemRect
( item
) );
r.setTop( std::max( r.top(), 0 ) );
r.setLeft( std::max( r.left(), 0 ) );
r.setHeight( std::max( f_list_view->viewport()->height(), r.height() ) );
r.setWidth( std::min( f_list_view->viewport()->width(), r.width() ) );
point = f_list_view->viewport()->mapToParent( r.topLeft() );
r.setTopLeft( point );
r.setHeight( std::max( f_list_view->height(), r.height() ) );
r.setWidth( std::min( f_list_view->width(), r.width() ) );
qDebug( "void n_list_view_tooltip::maybeTip( %d, %d ): rect = (%d,%d,%d,%d); tip='%s'", p.x(), p.y(), r.top(), r.left(), r.width(), r.height(), ( const char * ) s.utf8() );
tip( r, s );
}
#include "n_list_view_tooltip.h"
#include <qheader.h>
n_list_view_tooltip::n_list_view_tooltip( QListView * widget, QToolTipGroup * group ):
QToolTip( widget, group ), f_list_view( widget )
{
}
n_list_view_tooltip::~ n_list_view_tooltip( )
{
if ( f_list_view )
remove( f_list_view );
}
QListView * n_list_view_tooltip::list_view( ) const
{
return f_list_view;
}
void n_list_view_tooltip::set_list_view( QListView * value )
{
f_list_view = value;
}
void n_list_view_tooltip::maybeTip( const QPoint & p )
{
if ( !f_list_view )
{
qDebug( "void n_list_view_tooltip::maybeTip( %d, %d ): f_list_view is NULL", p.x(), p.y() );
return;
}
if ( ! f_list_view->viewport()->rect().contains( p ) )
{
qDebug( "void n_list_view_tooltip::maybeTip( %d, %d ): viewport does not contain p!", p.x(), p.y() );
return;
}
QPoint point( f_list_view->viewport()->mapFromParent( p ) );
QListViewItem * item = f_list_view->itemAt( point );
if ( !item )
{
qDebug( "void n_list_view_tooltip::maybeTip( %d, %d ): item is NULL", p.x(), p.y() );
return;
}
QString s = item->text( f_list_view->header()->sectionAt( point.x() ) );
QRect r( f_list_view->itemRect( item ) );
r.setTop( std::max( r.top(), 0 ) );
r.setLeft( std::max( r.left(), 0 ) );
r.setHeight( std::max( f_list_view->viewport()->height(), r.height() ) );
r.setWidth( std::min( f_list_view->viewport()->width(), r.width() ) );
point = f_list_view->viewport()->mapToParent( r.topLeft() );
r.setTopLeft( point );
r.setHeight( std::max( f_list_view->height(), r.height() ) );
r.setWidth( std::min( f_list_view->width(), r.width() ) );
qDebug( "void n_list_view_tooltip::maybeTip( %d, %d ): rect = (%d,%d,%d,%d); tip='%s'", p.x(), p.y(), r.top(), r.left(), r.width(), r.height(), ( const char * ) s.utf8() );
tip( r, s );
}
To copy to clipboard, switch view to plain text mode
Bookmarks