QDesignerLabel Class Reference

#include <qdesigner_widget_p.h>

Inheritance diagram for QDesignerLabel:

Inheritance graph
[legend]
Collaboration diagram for QDesignerLabel:

Collaboration graph
[legend]
List of all members.

Detailed Description

Definition at line 95 of file qdesigner_widget_p.h.

Public Member Functions

 QDesignerLabel (QWidget *parent=0)
void setBuddy (const QByteArray &b)
QByteArray buddy () const
void setBuddy (QWidget *widget)

Protected Member Functions

void showEvent (QShowEvent *e)

Private Member Functions

void updateBuddy ()

Private Attributes

QByteArray myBuddy


Constructor & Destructor Documentation

QDesignerLabel::QDesignerLabel ( QWidget parent = 0  ) 

Definition at line 149 of file qdesigner_widget.cpp.

00150     : QLabel(parent)
00151 {
00152 }


Member Function Documentation

void QDesignerLabel::setBuddy ( const QByteArray b  )  [inline]

Definition at line 102 of file qdesigner_widget_p.h.

References b.

00103     {
00104         myBuddy = b;
00105         updateBuddy();
00106     }

QByteArray QDesignerLabel::buddy (  )  const [inline]

Returns this label's buddy, or 0 if no buddy is currently set.

See also:
setBuddy()

Reimplemented from QLabel.

Definition at line 108 of file qdesigner_widget_p.h.

00109     { return myBuddy; }

void QDesignerLabel::setBuddy ( QWidget widget  ) 

Sets this label's buddy to buddy.

When the user presses the shortcut key indicated by this label, the keyboard focus is transferred to the label's buddy widget.

The buddy mechanism is only available for QLabels that contain plain text in which one character is prefixed with an ampersand, '&'. This character is set as the shortcut key. See the {QShortcut::mnemonic}{QShortcut} documentation for details (to display an actual ampersand, use '&&').

In a dialog, you might create two data entry widgets and a label for each, and set up the geometry layout so each label is just to the left of its data entry widget (its "buddy"), for example:

    QLineEdit *nameEd  = new QLineEdit(this);
    QLabel    *nameLb  = new QLabel("&Name:", this);
    nameLb->setBuddy(nameEd);
    QLineEdit *phoneEd = new QLineEdit(this);
    QLabel    *phoneLb = new QLabel("&Phone:", this);
    phoneLb->setBuddy(phoneEd);
    // (layout setup not shown)

With the code above, the focus jumps to the Name field when the user presses Alt+N, and to the Phone field when the user presses Alt+P.

To unset a previously set buddy, call this function with buddy set to 0.

See also:
buddy(), setText(), QShortcut, setAlignment()

Reimplemented from QLabel.

Definition at line 154 of file qdesigner_widget.cpp.

References QLabel::setBuddy().

00155 {
00156     QLabel::setBuddy(widget);
00157 }

Here is the call graph for this function:

void QDesignerLabel::showEvent ( QShowEvent e  )  [inline, protected, virtual]

This event handler can be reimplemented in a subclass to receive widget show events which are passed in the event parameter.

Non-spontaneous show events are sent to widgets immediately before they are shown. The spontaneous show events of windows are delivered afterwards.

Note: A widget receives spontaneous show and hide events when its mapping status is changed by the window system, e.g. a spontaneous hide event when the user minimizes the window, and a spontaneous show event when the window is restored again. After receiving a spontaneous hide event, a widget is still considered visible in the sense of isVisible().

See also:
visible, event(), QShowEvent

Reimplemented from QWidget.

Definition at line 114 of file qdesigner_widget_p.h.

References QWidget::showEvent().

00115     {
00116         QLabel::showEvent(e);
00117         updateBuddy();
00118     }

Here is the call graph for this function:

void QDesignerLabel::updateBuddy (  )  [private]

Definition at line 106 of file qdesigner_widget.cpp.

References QString::fromUtf8(), QByteArray::isEmpty(), myBuddy, QLabel::setBuddy(), and QWidget::topLevelWidget().

00107 {
00108     if (myBuddy.isEmpty()) {
00109         QLabel::setBuddy(0);
00110         return;
00111     }
00112 
00113     QList<QWidget *> widgets = qFindChildren<QWidget*>(topLevelWidget(), QString::fromUtf8(myBuddy));
00114     QListIterator<QWidget *> it(widgets);
00115     while (it.hasNext()) {
00116         QWidget *widget = it.next();
00117         if (widget && !widget->isHidden()) {
00118             QLabel::setBuddy(widget);
00119             return;
00120         }
00121     }
00122     QLabel::setBuddy(0);
00123 }

Here is the call graph for this function:


Member Data Documentation

QByteArray QDesignerLabel::myBuddy [private]

Definition at line 123 of file qdesigner_widget_p.h.

Referenced by updateBuddy().


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 17:15:50 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1