[Qt-interest] QLabel buddy and Custom Widget.
Bo Thorsen
bo at fioniasoftware.dk
Tue May 3 07:20:55 CEST 2011
Hi,
The real work happens here:
bool QLabel::event(QEvent *e)
{
Q_D(QLabel);
QEvent::Type type = e->type();
#ifndef QT_NO_SHORTCUT
if (type == QEvent::Shortcut) {
QShortcutEvent *se = static_cast<QShortcutEvent *>(e);
if (se->shortcutId() == d->shortcutId) {
QWidget * w = d->buddy;
QAbstractButton *button = qobject_cast<QAbstractButton *>(w);
if (w->focusPolicy() != Qt::NoFocus)
w->setFocus(Qt::ShortcutFocusReason);
if (button && !se->isAmbiguous())
button->animateClick();
else
window()->setAttribute(Qt::WA_KeyboardFocusChange);
return true;
}
You found the buddy attribute there, so you were almost there. You just
had to run a search to find out what happens. "Happens" is usually in an
event handler (mouse, change, etc.).
If they wanted to, they could have implemented the mouse handlers as
well, so mouseclicks would activate the buddy as well, but they have
chosen not to do this.
But I hope you have what you need now.
Bo.
Den 02-05-2011 18:33, NaGeL skrev:
> I did. And i said i looked at the headers files, and now too.
>
> this is QLabel's setbuddy function:
>
> void QLabel::setBuddy(QWidget *buddy)
> {
> Q_D(QLabel);
> d->buddy = buddy;
> if (d->isTextLabel) {
> if (d->shortcutId)
> releaseShortcut(d->shortcutId);
> d->shortcutId = 0;
> d->textDirty = true;
> if (buddy)
> d->updateShortcut(); // grab new shortcut
> d->updateLabel();
> }
> }
>
> what i understand from it is: its sets its buddy, and refreshes it
> shourtcuts, the shortcut that will give focus to the widget.
>
> but this is what I'm asking.... how can i redirect the focus of the
> shortcut to my Widget's QTextEdit?
>
> I figured its Q_PROPERTY thing like it was with the mapping question I
> had... setFocus, setFocusProxy.. doesn't really works...
>
> 2011/5/2 Bo Thorsen <bo at fioniasoftware.dk <mailto:bo at fioniasoftware.dk>>
>
> Den 01-05-2011 18:01, NaGeL skrev:
>
> Hello its the newb again.
>
> And now i would like to ask. How does QLAbel's buddy function works?
> And how can I get it to work with my Custom Widget?
>
> My Widget Contains several tool button and a QTextEdit.
> I want to set QLabel's buddy the QTextEit, that is inside my
> Custom Widget.
>
> is this too a Q_Property stuff? if yes how? i looked into the
> QLabel's
> header and QTextEdits header files but i failed to find any
> indication...
>
>
> I don't know this, but I know how I would find out: Read the Qt
> sourcecode. This is a perfect case of a problem that most likely
> will take you no longer than maximum 10 minutes to figure out by
> looking at the QLabel sources.
>
> I'm not trying to be clever here. This is a tool I use very often,
> and I think it's important to keep reminding people that it's available.
>
> Bo Thorsen,
> Fionia Software.
>
> --
>
> Expert Qt and C++ developer for hire
> Contact me if you need expert Qt help
> http://www.fioniasoftware.dk
>
>
Bo Thorsen,
Fionia Software.
--
Expert Qt and C++ developer for hire
Contact me if you need expert Qt help
http://www.fioniasoftware.dk
More information about the Qt-interest-old
mailing list