KDE 4.7 PyKDE API Reference

- KDE's Python API

# KUrlLabel Class Reference

`from PyKDE4.kdeui import *`

Inherits: QLabel → QFrame → QWidget → QObject

## Detailed Description

A drop-in replacement for QLabel that displays hyperlinks.

KUrlLabel is a drop-in replacement for QLabel that handles text in a fashion similar to how an HTML widget handles hyperlinks. The text can be underlined (or not) and set to different colors. It can also "glow" (cycle colors) when the mouse passes over it.

KUrlLabel also provides signals for several events, including the mouse leaving and entering the text area and all forms of mouse clicking.

By default KUrlLabel accepts focus. When focused, standard focus rectangle is displayed as in HTML widget. Pressing Enter key accepts the focused label.

A typical usage would be something like so:

     KUrlLabel *address = new KUrlLabel(this);
     address->setText("My homepage");
     address->setUrl("http://www.home.com/~me");
     connect(address, SIGNAL(leftClickedUrl(const QString&)),
                      SLOT(processMyUrl(const QString&)));

In this example, the text "My homepage" would be displayed as blue, underlined text. When the mouse passed over it, it would "glow" red. When the user clicks on the text, the signal leftClickedUrl() would be emitted with "http://www.home.com/~me" as its argument.

"KDE URL Label"

Author:
  Kurt Granroth <granroth@kde.org> (Interface)

Author:
  Peter Putzer <putzer@kde.org> (Rewrite)

## Signals
| enteredUrl (QString url)
| enteredUrl ()
| leftClickedUrl (QString url)
| leftClickedUrl ()
| leftUrl (QString url)
| leftUrl ()
| middleClickedUrl (QString url)
| middleClickedUrl ()
| rightClickedUrl (QString url)
| rightClickedUrl ()
## Methods
| __init__ (self, QWidget parent=0)
| __init__ (self, QString url, QString text=QString(), QWidget parent=0)
QPixmap | alternatePixmap (self)
| enterEvent (self, QEvent a0)
bool | event (self, QEvent a0)
bool | isFloatEnabled (self)
bool | isGlowEnabled (self)
| leaveEvent (self, QEvent a0)
| mouseReleaseEvent (self, QMouseEvent a0)
| setAlternatePixmap (self, QPixmap pixmap)
| setFloatEnabled (self, bool do_float=1)
| setFont (self, QFont font)
| setGlowEnabled (self, bool glow=1)
| setHighlightedColor (self, QColor highcolor)
| setHighlightedColor (self, QString highcolor)
| setSelectedColor (self, QColor color)
| setSelectedColor (self, QString color)
| setTipText (self, QString tip)
| setUnderline (self, bool on=1)
| setUrl (self, QString url)
| setUseCursor (self, bool on, QCursor cursor=0)
| setUseTips (self, bool on=1)
QString | tipText (self)
QString | url (self)
bool | useCursor (self)
bool | useTips (self)

## Signal Documentation

enteredUrl | ( | QString | url
| ) |  |  |

Emitted when the mouse has passed over the label.

Signal syntax:
  `QObject.connect(source, SIGNAL("enteredUrl(const QString&)"), target_slot)`

enteredUrl | ( |  | ) |

Emitted when the mouse has passed over the label.

Signal syntax:
  `QObject.connect(source, SIGNAL("enteredUrl()"), target_slot)`

leftClickedUrl | ( | QString | url
| ) |  |  |

Emitted when the user clicked the left mouse button on this label.

Signal syntax:
  `QObject.connect(source, SIGNAL("leftClickedUrl(const QString&)"), target_slot)`

leftClickedUrl | ( |  | ) |

Emitted when the user clicked the left mouse button on this label.

Signal syntax:
  `QObject.connect(source, SIGNAL("leftClickedUrl()"), target_slot)`

leftUrl | ( | QString | url
| ) |  |  |

Emitted when the mouse is no longer over the label.

Signal syntax:
  `QObject.connect(source, SIGNAL("leftUrl(const QString&)"), target_slot)`

leftUrl | ( |  | ) |

Emitted when the mouse is no longer over the label.

Signal syntax:
  `QObject.connect(source, SIGNAL("leftUrl()"), target_slot)`

middleClickedUrl | ( | QString | url
| ) |  |  |

Emitted when the user clicked the left mouse button on this label.

Signal syntax:
  `QObject.connect(source, SIGNAL("middleClickedUrl(const QString&)"), target_slot)`

middleClickedUrl | ( |  | ) |

Emitted when the user clicked the left mouse button on this label.

Signal syntax:
  `QObject.connect(source, SIGNAL("middleClickedUrl()"), target_slot)`

rightClickedUrl | ( | QString | url
| ) |  |  |

Emitted when the user clicked the right mouse button on this label.

Signal syntax:
  `QObject.connect(source, SIGNAL("rightClickedUrl(const QString&)"), target_slot)`

rightClickedUrl | ( |  | ) |

Emitted when the user clicked the right mouse button on this label.

Signal syntax:
  `QObject.connect(source, SIGNAL("rightClickedUrl()"), target_slot)`

## Method Documentation

__init__ | ( | self, |
|  | QWidget | parent=0
| ) |  |  |

Default constructor.

Use setUrl() and setText() or QListView.setPixmap() to set the resp. properties.

__init__ | ( | self, |
|  | QString | url,
|  | QString | text=QString(),
|  | QWidget | parent=0
| ) |  |  |

Convenience constructor.

Parameters:

  | url | is the URL emitted when the label is clicked.
  | text | is the displayed string. If it's equal to QString() the url will be used instead.
  | parent | Passed to lower level constructor

parent and name are passed to QLabel, which in turn passes them further down

QPixmap alternatePixmap | ( |  | self ) |

Returns:
  the alternate pixmap (may be 0L if none was set).

enterEvent | ( | self, |
|  | QEvent | a0
| ) |  |  |

Overridden for internal reasons; the API remains unaffected.

bool event | ( | self, |
|  | QEvent | a0
| ) |  |  |

Catch parent palette changes

bool isFloatEnabled | ( |  | self ) |

This feature is very similar to the "glow" feature in that the color of the label switches to the selected color when the cursor passes over it. In addition, underlining is turned on for as long as the mouse is overhead. Note that if "glow" and underlining are both already turned on, this feature will have no visible effect.

bool isGlowEnabled | ( |  | self ) |

When this is on, the text will switch to the selected color whenever the mouse passes over it.

leaveEvent | ( | self, |
|  | QEvent | a0
| ) |  |  |

Overridden for internal reasons; the API remains unaffected.

mouseReleaseEvent | ( | self, |
|  | QMouseEvent | a0
| ) |  |  |

Overridden for internal reasons; the API remains unaffected.

setAlternatePixmap | ( | self, |
|  | QPixmap | pixmap
| ) |  |  |

Sets the "alt" pixmap.

This pixmap will be displayed when the cursor passes over the label. The effect is similar to the trick done with 'onMouseOver' in javascript.

See also:
  alternatePixmap()

setFloatEnabled | ( | self, |
|  | bool | do_float=1
| ) |  |  |

Turns on or off the "float" feature.

This feature is very similar to the "glow" feature in that the color of the label switches to the selected color when the cursor passes over it. In addition, underlining is turned on for as long as the mouse is overhead. Note that if "glow" and underlining are both already turned on, this feature will have no visible effect. By default, it is false.

setFont | ( | self, |
|  | QFont | font
| ) |  |  |

Overridden for internal reasons; the API remains unaffected.

setGlowEnabled | ( | self, |
|  | bool | glow=1
| ) |  |  |

Turns on or off the "glow" feature.

When this is on, the text will switch to the selected color whenever the mouse passes over it. By default, it is true.

setHighlightedColor | ( | self, |
|  | QColor | highcolor
| ) |  |  |

This is an overloaded version for convenience.

See also:
  setHighlightedColor()

setHighlightedColor | ( | self, |
|  | QString | highcolor
| ) |  |  |

This is an overloaded version for convenience.

See also:
  setHighlightedColor()

setSelectedColor | ( | self, |
|  | QColor | color
| ) |  |  |

This is an overloaded version for convenience.

See also:
  setSelectedColor()

setSelectedColor | ( | self, |
|  | QString | color
| ) |  |  |

This is an overloaded version for convenience.

See also:
  setSelectedColor()

setTipText | ( | self, |
|  | QString | tip
| ) |  |  |

Specifies what text to display when tooltips are turned on.

If this is not used, the tip will default to the URL.

See also:
  setUseTips()

setUnderline | ( | self, |
|  | bool | on=1
| ) |  |  |

Turns on or off the underlining.

When this is on, the text will be underlined. By default, it is true.

setUrl | ( | self, |
|  | QString | url
| ) |  |  |

Sets the URL for this label to url.

See also:
  url

setUseCursor | ( | self, |
|  | bool | on,
|  | QCursor | cursor=0
| ) |  |  |

Turns the custom cursor feature on or off.

When this is on, the cursor will change to a custom cursor (default is a "pointing hand") whenever the cursor passes over the label. By default, it is on.

Parameters:

  | on | whether a custom cursor should be displayed.
  | cursor | is the custom cursor. 0L indicates the default "hand cursor".

setUseTips | ( | self, |
|  | bool | on=1
| ) |  |  |

Turns on or off the tool tip feature.

When this is on, the URL will be displayed as a tooltip whenever the mouse passes passes over it. By default, it is false.

QString tipText | ( |  | self ) |

Returns the current tooltip text.

QString url | ( |  | self ) |

Returns the URL.

bool useCursor | ( |  | self ) |

Returns:
  true if the cursor will change while over the URL.

See also:
  setUseCursor ()

bool useTips | ( |  | self ) |

Returns:
  true if a tooltip will be displayed.

See also:
  setTipText()