Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Archived:Improving the usability of spin boxes on Qt for Symbian touch devices

From Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Qt Quick should be used for all UI development on mobile devices. The approach described in this article (based on QWidget) is deprecated.

Article Metadata
Tested with
Devices(s): All (S60)
Platform(s): S60 5th Edition
Qt 4.6.2
S60 5th Edition
Keywords: QSpinBox, QDoubleSpinBox, installEventFilter
Created: User:Kbwiki (10 May 2010)
Last edited: hamishwillee (11 Oct 2012)


This article shows how to the usability of Qt spin boxes (QSpinBox) on Symbian touch devices.


Qt provides QSpinBox and QDoubleSpinBox widgets that allow the user to input integer and double values, respectively. The value can be modified by clicking the up and down buttons, or by clicking on the line edit field of the spin box and entering a new value manually.

When clicking on the line edit field on Symbian devices, the user has to remove the old value either by using backspace or by selecting the entire contents of the edit field before a new value can be entered. In Symbian devices with a keyboard, this is not so much a problem as pressing up or down on the navigation keys will auto-select all the text in the edit field.

On Symbian touch devices, this additional step can be avoided by automatically selecting all text when receiving a mouse press event in the line edit (QLineEdit) widget of the spin box field; the user can proceed to input new numbers directly after touching the edit field of a spin box.


Create a custom spin box class by inheriting from QSpinBox or QDoubleSpinBox, and install an event filter to intercept mouse press events:

  #include <QDoubleSpinBox>
#include <QLineEdit>
#include <QTimer>
#include <QEvent>
class MySpinBox : public QDoubleSpinBox
explicit MySpinBox( QWidget *parent = 0 );
~MySpinBox() {}
bool eventFilter( QObject *obj, QEvent *event );
MySpinBox::MySpinBox( QWidget *parent ) :
QDoubleSpinBox( parent )
lineEdit()->installEventFilter( this );
bool MySpinBox::eventFilter( QObject *obj, QEvent *event )
if ( event->type() == QEvent::MouseButtonPress ) {
// select all content in line edit widget after 250ms
QTimer::singleShot( 250, lineEdit(), SLOT( selectAll() ) );
// standard event processing
return QObject::eventFilter( obj, event );
This page was last modified on 11 October 2012, at 01:14.
46 page views in the last 30 days.