PDA

View Full Version : QSpinBox and returnPressed() Signal



BeS
14th October 2006, 01:07
Hi,
I have a small Qt4 program, for the GUI i have used the designer. Basically the program has some input-widgets and a calculate-button which calculates some things from the input.
The last input-widget is a QSpinbox. Now i want the additional option to start the calculation by pressing return in the QSpinBox but QSpinBox doesn't have such a signal. Through QAbstractSpinBox i can access the QLineEdit which has a returnClicked() signal.

With the Designer i can't connect the signal with the calculate-button and if i try to connect it in the code:


QObject::connect(ui.reachedSpinBox->lineEdit(), SIGNAL(returnPressed()),
ui.calcButton, SLOT(click()));


i get this error message:


mainwindow.cpp: In constructor ‘MainWindow::MainWindow(Marks*, QWidget*)’:
/usr/include/qt4/QtGui/qabstractspinbox.h:114: error: ‘QLineEdit* QAbstractSpinBox::lineEdit() const’ is protected
mainwindow.cpp:12: error: within this context


Someone already told me that probably i have to inherit from QSpinBox and then emit a own signal if the lineEdit emits the returnPressed() signal.

But because this program is fairly small i want to avoid this effort (Inherit my own SpinBox from QSpinBox would be as large as the whole program just to get the returnPressed() signal).

So i ask you if there is any other option to confirm the input in a QSpinBox and respond on it? I can't believe that Qt has input-widgets which don't provides a option to respond on a keypress event.

Thanks!

jacek
14th October 2006, 18:07
You can install an event filter and catch any event you want. See QObject::installEventFilter() docs.

BeS
14th October 2006, 19:23
Thank you, QObject::installEventFilter() works really well for me!