Namespaces

Variants
Actions

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 over the next few weeks. 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)
Compatibility
Platform(s): S60 5th Edition
Qt 4.6.2
Symbian
S60 5th Edition
Article
Keywords: QSpinBox, QDoubleSpinBox, installEventFilter
Created: User:Kbwiki (10 May 2010)
Last edited: hamishwillee (11 Oct 2012)

Overview

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

Description

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.


Solution

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
{
Q_OBJECT
public:
explicit MySpinBox( QWidget *parent = 0 );
~MySpinBox() {}
 
protected:
bool eventFilter( QObject *obj, QEvent *event );
};
 
 
MySpinBox::MySpinBox( QWidget *parent ) :
QDoubleSpinBox( parent )
{
#ifdef Q_OS_SYMBIAN
lineEdit()->installEventFilter( this );
#endif
}
 
 
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.
66 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×