⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qtooltip.cpp

📁 qtopia-phone-2.2.0下公共的控件实现源代码。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    currentTip = 0;    if ( previousTip && previousTip->autoDelete )	remove( widget, previousTip->rect );    if ( !widget.isNull() )	// QGuardedPtr::operator=() is costly in 2.3	widget = 0;}void  QTipManager::hideTipAndSleep(){    hideTip();    fallAsleep.stop();}void QTipManager::allowAnimation(){    preventAnimation = FALSE;}// NOT REVISED/*!  \class QToolTip qtooltip.h  \brief The QToolTip class provides tool tips (sometimes called  balloon help) for any widget or rectangular part of a widget.  \ingroup helpsystem  The tip is a short, one-line text reminding the user of the widget's  or rectangle's function.  It is drawn immediately below the region,  in a distinctive black on yellow combination.  In Motif style, Qt's  tool tips look much like Motif's but feel more like Windows 95 tool  tips.  QToolTipGroup provides a way for tool tips to display another text  elsewhere (most often in a status bar).  At any point in time, QToolTip is either dormant or active.  In  dormant mode the tips are not shown, and in active mode they are.  The mode is global, not particular to any one widget.  QToolTip switches from dormant to active mode when the user lets the  mouse rest on a tip-equipped region for a second or so, and remains  in active mode until the user either clicks a mouse button, presses  a key, lets the mouse rest for five seconds, or moves the mouse  outside \e all tip-equpped regions for at least a second.  The QToolTip class can be used in three different ways: <ol> <li>  Adding a tip to an entire widget. <li> Adding a tip to a fixed  rectangle within a widget. <li> Adding a tip to a dynamic rectangle  within a widget. </ol>  To add a tip to a widget, call the \e static function QToolTip::add()  with the widget and tip as arguments:  \code    QToolTip::add( quitButton, "Leave the application" );  \endcode  This is the simplest and most common use of QToolTip.  The tip will  be deleted automatically when \e quitButton is deleted, but you can  remove it yourself, too:  \code    QToolTip::remove( quitButton );  \endcode  You can also display another text (typically in a \link QStatusBar  status bar),\endlink courtesy of QToolTipGroup.  This example  assumes that \e g is a <code>QToolTipGroup *</code> and already  connected to the appropriate status bar:  \code    QToolTip::add( quitButton, "Leave the application", g,		   "Leave the application, without asking for confirmation" );    QToolTip::add( closeButton, "Close this window", g,		   "Close this window, without asking for confirmation" );  \endcode  To add a tip to a fixed rectangle within a widget, call the static  function QToolTip::add() with the widget, rectangle and tip as  arguments.  (See the tooltip/tooltip.cpp example.)  Again, you can supply a  QToolTipGroup * and another text if you want.  Both of the above are one-liners and cover the vast majority of  cases.  The third and most general way to use QToolTip uses a pure  virtual function to decide whether to pop up a tool tip.  The  tooltip/tooltip.cpp example demonstrates this too.  This mode can be  used to implement e.g. tips for text that can move as the user  scrolls.  To use QToolTip like this, you need to subclass QToolTip and  reimplement maybeTip().  maybeTip() will be called when there's a  chance that a tip should pop up.  It must decide whether to show a  tip, and possibly call add() with the rectangle the tip applies to,  the tip's text and optionally the QToolTipGroup details.  The tip  will disappear once the mouse moves outside the rectangle you  supply, and \e not \e reappear - maybeTip() will be called again if  the user lets the mouse rest within the same rectangle again.  You  can forcibly remove the tip by calling remove() with no arguments.  This is handy if the widget scrolls.  Tooltips can be globally disabled using QToolTip::setEnabled(), or  disabled in groups with QToolTipGroup::setEnabled().  \sa QStatusBar QWhatsThis QToolTipGroup  <a href="guibooks.html#fowler">GUI Design Handbook: Tool Tip</a>*//*  Global settings for tool tips.*/void QToolTip::initialize() // ## remove 3.0{}void QToolTip::cleanup() // ## remove 3.0{}/*!  Returns the font common to all tool tips.  \sa setFont()*/QFont QToolTip::font(){    QTipLabel l("");    return QApplication::font( &l );}/*!  Sets the font for all tool tips to \a font.  \sa font()*/void QToolTip::setFont( const QFont &font ){    QApplication::setFont( font, TRUE, "QTipLabel" );}/*!  Returns the palette common to all tool tips.  \sa setPalette()*/QPalette QToolTip::palette(){    QTipLabel l("");    return QApplication::palette( &l );}/*!  Sets the palette for all tool tips to \a palette.  \sa palette()*/void QToolTip::setPalette( const QPalette &palette ){    QApplication::setPalette( palette, TRUE, "QTipLabel" );}/*!  Constructs a tool tip object.  This is necessary only if you need tool  tips on regions that can move within the widget (most often because  the widget's contents can scroll).  \a parent is the widget you want to add dynamic tool tips to and \a  group (optional) is the tool tip group they should belong to.  \sa maybeTip().*/QToolTip::QToolTip( QWidget * parent, QToolTipGroup * group ){    p = parent;    g = group;    initTipManager();    tipManager->add( p, entireWidget(),		     QString::null, g, QString::null, this, FALSE );}/*!  Adds a tool tip to \e widget.  \e text is the text to be shown in  the tool tip.  QToolTip makes a deep copy of this string.  This is the most common entry point to the QToolTip class; it is  suitable for adding tool tips to buttons, check boxes, combo boxes  and so on.*/void QToolTip::add( QWidget *widget, const QString &text ){    initTipManager();    tipManager->add( widget, entireWidget(),		     text, 0, QString::null, 0, FALSE );}/*!  Adds a tool tip to \a widget, and to tool tip group \a group.  \e text is the text shown in the tool tip and \a longText is the  text emitted from \a group.  QToolTip makes deep copies of both  strings.  Normally, \a longText is shown in a status bar or similar.*/void QToolTip::add( QWidget *widget, const QString &text,		    QToolTipGroup *group, const QString& longText ){    initTipManager();    tipManager->add( widget, entireWidget(), text, group, longText, 0, FALSE );}/*!  Remove the tool tip from \e widget.  If there are more than one tool tip on \a widget, only the one  covering the entire widget is removed.*/void QToolTip::remove( QWidget * widget ){    if ( tipManager )	tipManager->remove( widget, entireWidget() );}/*!  Adds a tool tip to a fixed rectangle within \a widget.  \a text is  the text shown in the tool tip.  QToolTip makes a deep copy of this  string.*/void QToolTip::add( QWidget * widget, const QRect & rect, const QString &text ){    initTipManager();    tipManager->add( widget, rect, text, 0, QString::null, 0, FALSE );}/*!  Adds a tool tip to an entire \a widget, and to tool tip group \a  group.  \e text is the text shown in the tool tip and \a longText is the  text emitted from \a group.  QToolTip makes deep copies of both  strings.  Normally, \a longText is shown in a status bar or similar.*/void QToolTip::add( QWidget *widget, const QRect &rect,		    const QString& text,		    QToolTipGroup *group, const QString& groupText ){    initTipManager();    tipManager->add( widget, rect, text, group, groupText, 0, FALSE );}/*!  Remove the tool tip for \e rect from \e widget.  If there are more than one tool tip on \a widget, only the one  covering rectangle \e rect is removed.*/void QToolTip::remove( QWidget * widget, const QRect & rect ){    if ( tipManager )	tipManager->remove( widget, rect );}/*!  Hides any tip that is currently being shown.  Normally, there is no need to call this function; QToolTip takes  care of showing and hiding the tips as the user moves the mouse.*/void QToolTip::hide(){    if ( tipManager )	tipManager->hideTipAndSleep();}/*!  \fn virtual void QToolTip::maybeTip( const QPoint & p);  This pure virtual function is half of the most versatile interface  QToolTip offers.  It is called when there is a chance that a tool tip should be shown,  and must decide whether there is a tool tip for the point \a p in  the widget this QToolTip object relates to.  \a p is given in that widget's local coordinates.  Most maybeTip()  implementation will be of the form:  \code    if ( <something> ) {	tip( <something>, <something> );    }  \endcode  The first argument to tip() (a rectangle) should include the \a p,  or QToolTip, the user or both can be confused.  \sa tip()*//*!  Pops up a tip saying \a text right now, and removes that tip once  the cursor moves out of rectangle \a rect (which is given in the  coordinate system of the widget this QToolTip relates to).  The tip will not come back if the cursor moves back; your maybeTip()  has to reinstate it each time.*/void QToolTip::tip( const QRect & rect, const QString &text ){    initTipManager();    tipManager->add( parentWidget(), rect, text, 0, QString::null, 0, TRUE );}void QToolTip::tip( const QRect &geometry, const QRect &rect, const QString &text ){    initTipManager();    tipManager->add( geometry, parentWidget(), rect, text, 0, QString::null, 0, TRUE );}/*!  Pops up a tip saying \a text right now, and removes that tip once  the cursor moves out of rectangle \a rect.  The tip will not come back if the cursor moves back; your maybeTip()  has to reinstate it each time.*/void QToolTip::tip( const QRect & rect, const QString &text,		    const QString& groupText ){    initTipManager();    tipManager->add( parentWidget(), rect, text, group(), groupText, 0, TRUE );}/*!  Removes all tool tips for this tooltip's parent widget immediately.*/void QToolTip::clear(){    if ( tipManager )	tipManager->remove( parentWidget() );}/*!  \fn QWidget * QToolTip::parentWidget() const  Returns the widget this QToolTip applies to.  The tool tip is destroyed automatically when the parent widget is  destroyed.  \sa group()*//*!  \fn QToolTipGroup * QToolTip::group() const  Returns the tool tip group this QToolTip is a member of, of 0 if it  isn't a member of any group.  The tool tip group is the object responsible for relaying contact  between tool tips and a status bar or something else which can show  a longer help text.  \sa parentWidget(), QToolTipGroup*//*!  \class QToolTipGroup qtooltip.h  \brief The QToolTipGroup class collects tool tips into natural groups.  \ingroup helpsystem  Tool tips can display \e two texts, the one in the tip and  optionally another one, typically in a status bar.  QToolTipGroup  provides a way to link tool tips to this status bar.  QToolTipGroup has practically no API, it is only used as an argument  to QToolTip's member functions, for example like this:  \code    QToolTipGroup * g = new QToolTipGroup( this, "tool tip relay" );    connect( g, SIGNAL(showTip(const QString&)),	     myLabel, SLOT(setText(const QString&)) );    connect( g, SIGNAL(removeTip()),	     myLabel, SLOT(clear()) );    QToolTip::add( giraffeButton, "feed giraffe",		   g, "Give the giraffe a meal" );    QToolTip::add( gorillaButton, "feed gorilla",		   g, "Give the gorilla a meal" );  \endcode  This example makes the object myLabel (which you have to supply)  display (one assumes, though you can make myLabel do anything, of  course) the strings "Give the giraffe a meal" and "Give the gorilla  a meal" while the relevant tool tips are being displayed.  Deleting a tool tip group removes the tool tips in it.*//*! \fn void QToolTipGroup::showTip (const QString &longText)  This signal is emitted when one of the tool tips in the group is  displayed.  \a longText is the supplementary text for the displayed  tool tip.  \sa removeTip()*//*! \fn void QToolTipGroup::removeTip ()  This signal is emitted when a tool tip in this group is hidden.  See  the QToolTipGroup documentation for an example of use.  \sa showTip()*//*!  Constructs a tool tip group.*/QToolTipGroup::QToolTipGroup( QObject *parent, const char *name )    : QObject( parent, name ){    del = TRUE;    ena = TRUE;}/*!  Destroy this tool tip groups and all tool tips in it.*/QToolTipGroup::~QToolTipGroup(){    if ( tipManager )	tipManager->removeFromGroup( this );}/*!  Returns TRUE if the group text is shown delayed (at the same timeas the tip) and FALSE if it is shown immediately.\sa setDelay()*/bool QToolTipGroup::delay() const{    return del;}/*!  Sets the group to show its text immediately if \a enable isFALSE, and delayed (at the same time as the tip text) if \a enable isTRUE.  The default is TRUE.\sa delay()*/void QToolTipGroup::setDelay( bool enable ){#if 0    if ( enable && !del ) {	// maybe we should show the text at once?    }#endif    del = enable;}/*!  Sets the group to be enabled (all tool tips in the group show  when activated),  or disabled (tool tips in the group are never shown).  \sa QToolTip::setEnabled(), enabled()*/void QToolTipGroup::setEnabled( bool enable ){    ena = enable;}/*!  Returns whether tooltips in the group are enabled.  \sa setEnabled()*/bool QToolTipGroup::enabled() const{    return (bool)ena;}/*!  Sets the all tool tips to be enabled (shown when needed)  or disabled (never shown).  By default, tool tips are enabled. Note that this function  effects all tooltips in the entire application.  \sa QToolTipGroup::setEnabled()*/void QToolTip::setEnabled( bool enable ){    globally_enabled = enable;}/*!  Returns whether tooltips are enabled globally.  \sa setEnabled()*/bool QToolTip::enabled(){    return globally_enabled;}#include "qtooltip.moc"#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -