| Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date | |
| All threads index page 2 | |
Hello,
I'm trying to find out how to activate combo box item by key press. When
combo box has focus and I press some key and item starting with this key
exists I receive activated signal, that's ok.
But I would like to receive it too when selecting item this way from
combo box popup. Pressing key in popup just highlight item but does not
activate it. I tried to solve it with event filter with no success. I
made this example:
#include "MainWindow.h"
cMainWindow::cMainWindow()
{
setupUi(this);
qcbTest->installEventFilter(this);
qcbTest->addItem("a");
qcbTest->addItem("b");
qcbTest->addItem("c");
} // cMainWindow
// event filter
bool cMainWindow::eventFilter(QObject *watched, QEvent *event)
{
if (watched == qcbTest) {
if (event->type() == QEvent::KeyPress) {
close();
} else {
return false;
} // if else
} else {
return QMainWindow::eventFilter(watched, event);
} // if else
} // eventFilter
So... when qcbTest (my QComboBox) has focus and I press 'a', 'b' or 'c'
I receive KeyPress event and application exits. But when I show popup
and press the key there no KeyPress event is received. Maybe the popup
is some kind of widget (QMenu) and I need to receive events from it but
I can't find how can I install event filter there.
Maybe possible solution is to use my own QMenu and show it instead of
QComboBox popup but that's not very good I think :) .
So is possible to activate it from popup somehow or only by some
workaround? Thank you for your help.
Isshou
--
[ signature omitted ]
Isshou wrote:
> Hello,
> I'm trying to find out how to activate combo box item by key press. When
> combo box has focus and I press some key and item starting with this key
> exists I receive activated signal, that's ok.
> But I would like to receive it too when selecting item this way from
> combo box popup. Pressing key in popup just highlight item but does not
> activate it. I tried to solve it with event filter with no success. I
> made this example:
>
> #include "MainWindow.h"
>
> cMainWindow::cMainWindow()
> {
> setupUi(this);
> qcbTest->installEventFilter(this);
>
> qcbTest->addItem("a");
> qcbTest->addItem("b");
> qcbTest->addItem("c");
> } // cMainWindow
>
> // event filter
> bool cMainWindow::eventFilter(QObject *watched, QEvent *event)
> {
> if (watched == qcbTest) {
> if (event->type() == QEvent::KeyPress) {
> close();
> } else {
> return false;
> } // if else
> } else {
> return QMainWindow::eventFilter(watched, event);
> } // if else
> } // eventFilter
>
> So... when qcbTest (my QComboBox) has focus and I press 'a', 'b' or 'c'
> I receive KeyPress event and application exits. But when I show popup
> and press the key there no KeyPress event is received. Maybe the popup
> is some kind of widget (QMenu) and I need to receive events from it but
> I can't find how can I install event filter there.
> Maybe possible solution is to use my own QMenu and show it instead of
> QComboBox popup but that's not very good I think :) .
> So is possible to activate it from popup somehow or only by some
> workaround? Thank you for your help.
>
> Isshou
>
> --
> 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/
>
You should create and install your own view (the popup widget that appears when you click on the
combo) and do the event handling there. Look at this:
http://doc.trolltech.com/4.2/qcombobox.html#setView
--stathis
Attachment:
Attachment:
smime.p7s
Description: S/MIME Cryptographic Signature
Message 3 in thread
Thank you very much, works great :) .
Stathis napsal(a):
> Isshou wrote:
>
> You should create and install your own view (the popup widget that
> appears when you click on the combo) and do the event handling there.
> Look at this:
>
> http://doc.trolltech.com/4.2/qcombobox.html#setView
>
> --stathis
>
>
>
--
[ signature omitted ]