Qt-interest Archive, January 2007
QDoubleSpinBox focus signal
Message 1 in thread
Do Qt 4.x widgets emit signals for focus events? I need to perform validation
actions when a QDoubleSpinBox gains and loses focus, and I don't see anything
in the docs about focus signals.
The only thing I can find in this regard (as has been the case for most of
Qt's history) is subclassing a widget just to get the focus events. This has
been a gaping flaw in Qt which I hope has been fixed in 4.x.
--
[ signature omitted ]
Message 2 in thread
Hi,
Tony O'Bryan wrote:
> Do Qt 4.x widgets emit signals for focus events? I need to perform validation
> actions when a QDoubleSpinBox gains and loses focus, and I don't see anything
> in the docs about focus signals.
>
> The only thing I can find in this regard (as has been the case for most of
> Qt's history) is subclassing a widget just to get the focus events. This has
> been a gaping flaw in Qt which I hope has been fixed in 4.x.
Can't you install an event filter on the widget in question to get the
focus notification? Look at QObject::eventFilter and
QObject::installEventFilter. I think this functionality been around for
a long time, certainly since Qt2.
Hope that helps,
Tim
--
[ signature omitted ]
Message 3 in thread
Tim is right, that's the way to do it.
So basically write an event Filter
#include "QtFocusInEventFilter.h"
#include <QtCore/QEvent>
FocusInEventFilter::FocusInEventFilter(QObject * receiver, const char *
member)
: QObject() {
SAFE_CONNECT_RECEIVER(this, SIGNAL(activate(QEvent *)),
receiver, member);
}
void FocusInEventFilter::filter(QEvent * event) {
activate(event);
}
FocusInEventFilter::FocusInEventFilter(QObject * receiver, const char *
member)
: EventFilter(receiver, member) {
}
bool FocusInEventFilter::eventFilter(QObject * watched, QEvent * event)
{
if (event->type() == QEvent::FocusIn) {
filter(event);
return true;
}
return EventFilter::eventFilter(watched, event);
}
Also receiver(parent of DoubleSpinBox) should have a slot like
FocusInEvent. This is how you install the event filter on some control
(QDoubleSpinBox) in your case
_doubleSpinBox->installEventFilter(new FocusInEventFilter(this,
SLOT(FocusInEvent())));
And in FocusEventSlot you can write whatever processing you want.
Doing it this was you don't have to typecast Qobject * to
QDoubleSpinBox* in your case.
Thanks,
Jaya
> -----Original Message-----
> From: Tim Dewhirst [mailto:tim@xxxxxxxxxxxxx]
> Sent: Thursday, January 11, 2007 4:52 PM
> To: Tony O'Bryan
> Cc: qt-interest@xxxxxxxxxxxxx
> Subject: Re: QDoubleSpinBox focus signal
>
> Hi,
>
> Tony O'Bryan wrote:
> > Do Qt 4.x widgets emit signals for focus events? I need to perform
> > validation actions when a QDoubleSpinBox gains and loses
> focus, and I
> > don't see anything in the docs about focus signals.
> >
> > The only thing I can find in this regard (as has been the case for
> > most of Qt's history) is subclassing a widget just to get the focus
> > events. This has been a gaping flaw in Qt which I hope has
> been fixed in 4.x.
>
> Can't you install an event filter on the widget in question
> to get the focus notification? Look at QObject::eventFilter
> and QObject::installEventFilter. I think this functionality
> been around for a long time, certainly since Qt2.
>
> Hope that helps,
>
> Tim
>
> --
> To unsubscribe - send a mail to
> qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the
> subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
--
[ signature omitted ]
Message 4 in thread
I didn't know about installEventFilter, and it indeed solved the problem
(thanks!). It is clumsy in relation to signals and slots, though, and I
still wish Trolltech would create signals on QWidget to handle it.
On Thursday 11 January 2007 3:52 pm, Tim Dewhirst wrote:
> Can't you install an event filter on the widget in question to get the
> focus notification? Look at QObject::eventFilter and
> QObject::installEventFilter. I think this functionality been around for
> a long time, certainly since Qt2.
>
> Hope that helps,
>
> Tim
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body. List archive and information:
> http://lists.trolltech.com/qt-interest/
--
[ signature omitted ]
Message 5 in thread
Hi,
I'd like such a signal, too. I already searched for it when I wanted a
MDI child window to know when it looses the focus, and I was really
surprised not to find it. I used another solution (using windowActivated
from QWorkspace), but I'd prefer signals for gaining and loosing focus.
Regards,
Ralf
Tony O'Bryan schrieb:
> I didn't know about installEventFilter, and it indeed solved the problem
> (thanks!). It is clumsy in relation to signals and slots, though, and I
> still wish Trolltech would create signals on QWidget to handle it.
>
> On Thursday 11 January 2007 3:52 pm, Tim Dewhirst wrote:
>
>> Can't you install an event filter on the widget in question to get the
>> focus notification? Look at QObject::eventFilter and
>> QObject::installEventFilter. I think this functionality been around for
>> a long time, certainly since Qt2.
>>
>> Hope that helps,
>>
>> Tim
>>
>> --
>> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
>> "unsubscribe" in the subject or the body. List archive and information:
>> http://lists.trolltech.com/qt-interest/
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
--
[ signature omitted ]
Message 6 in thread
You could pretty much write the same for any other kind of event -
others would like to have key events or resize events, or...
The split in Qt is actually simple: If it's a message that only concerns
one widget (aka going from the Qt system to a specific widget), it is an
event. If it's something that is communicated from the widget out to
others, it's a signal.
While it would sometimes be useful to grab the events, I do believe the
trolls have made the right decision on this one.
Bo.
Ralf Jung skrev:
> Hi,
>
> I'd like such a signal, too. I already searched for it when I wanted a
> MDI child window to know when it looses the focus, and I was really
> surprised not to find it. I used another solution (using windowActivated
> from QWorkspace), but I'd prefer signals for gaining and loosing focus.
>
> Regards,
> Ralf
>
> Tony O'Bryan schrieb:
>> I didn't know about installEventFilter, and it indeed solved the problem
>> (thanks!). It is clumsy in relation to signals and slots, though, and I
>> still wish Trolltech would create signals on QWidget to handle it.
>>
>> On Thursday 11 January 2007 3:52 pm, Tim Dewhirst wrote:
>>
>>> Can't you install an event filter on the widget in question to get the
>>> focus notification? Look at QObject::eventFilter and
>>> QObject::installEventFilter. I think this functionality been around for
>>> a long time, certainly since Qt2.
>>>
>>> Hope that helps,
>>>
>>> Tim
>>>
>>> --
>>> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
>>> "unsubscribe" in the subject or the body. List archive and information:
>>> http://lists.trolltech.com/qt-interest/
>> --
>> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
>> List archive and information: http://lists.trolltech.com/qt-interest/
>>
>
--
[ signature omitted ]
Message 7 in thread
On 1/11/07, Tony O'Bryan <TO'Bryan@xxxxxxxxxxxxxxxxxx> wrote:
> Do Qt 4.x widgets emit signals for focus events? I need to perform validation
> actions when a QDoubleSpinBox gains and loses focus, and I don't see anything
> in the docs about focus signals.
>
> The only thing I can find in this regard (as has been the case for most of
> Qt's history) is subclassing a widget just to get the focus events. This has
> been a gaping flaw in Qt which I hope has been fixed in 4.x.
The documentation (http://doc.trolltech.com/4.2/qabstractspinbox.html)
says there is a focus-out signal. There is also an overridable
validate() method specifically for validating the contents.
--
[ signature omitted ]