Results 1 to 3 of 3

Thread: QSpinBox and returnPressed() Signal

  1. #1
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    20
    Thanks
    2
    Thanked 4 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QSpinBox and returnPressed() Signal

    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:
    Qt Code:
    1. QObject::connect(ui.reachedSpinBox->lineEdit(), SIGNAL(returnPressed()),
    2. ui.calcButton, SLOT(click()));
    To copy to clipboard, switch view to plain text mode 

    i get this error message:
    Qt Code:
    1. mainwindow.cpp: In constructor ‘MainWindow::MainWindow(Marks*, QWidget*)’:
    2. /usr/include/qt4/QtGui/qabstractspinbox.h:114: error: ‘QLineEdit* QAbstractSpinBox::lineEdit() const’ is protected
    3. mainwindow.cpp:12: error: within this context
    To copy to clipboard, switch view to plain text mode 

    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!
    Last edited by BeS; 14th October 2006 at 01:12.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSpinBox and returnPressed() Signal

    You can install an event filter and catch any event you want. See QObject::installEventFilter() docs.

  3. The following 2 users say thank you to jacek for this useful post:

    BeS (14th October 2006), vieraci (8th June 2009)

  4. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    20
    Thanks
    2
    Thanked 4 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QSpinBox and returnPressed() Signal

    Thank you, QObject::installEventFilter() works really well for me!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.