Reply
Thread Tools
Posts: 5 | Thanked: 10 times | Joined on Feb 2010
#1
I'm working on a Qt 4.6 app for Maemo using a QWebView. I have a input type="text" field inside the QWebView and I would like it to accept only digits (like native input fields work - you don't have to hold the alt/fn arrow to type the numbers in).

I tried with Qt::InputMethodHints. Disabling auto complete and auto uppercase on all input fields displayed inside QWebView works with setting the inputMethodHints property on QWebView.
But, if I try to set it to allow only digits (Qt::ImhDigitsOnly), it does not have any effect. (If it would have an effect, I could then switch from digits mode to other modes with JS focusin and focusout events calling the javascript injected object to change the hints, since inputMethodHints property on QWebView affects all input fields on the displayed page).

There was a suggestion on #maemo to set type="number" on the input field (this is a new HTML5 feature), but that does not help much. Qt 4.6 QWebView treats such input field like normal text field (looks like the number type is not implemented yet).

Another option to consider is manually converting the inserted characters to numbers (q - 1, w - 2, e - 3, etc.), but this is ugly and will cause problems because of localisation differences. One would then have to implement conversions for all possible keyboard layouts - this is insane.

Any suggestions or hints?
 
Posts: 402 | Thanked: 229 times | Joined on Nov 2009 @ Missouri, USA
#2
QIntValidator
__________________
aspidites | blog | aspidites@inbox.com
 
Posts: 5 | Thanked: 10 times | Joined on Feb 2010
#3
Hm, I'm not sure if you really understand my problem. If it was a regular QLineEdit, things are relatively clear, the problem is that the input fields I'm trying to get hints working on are in HTML inside QWebView.

It would be great if it was somehow possible to switch ALT button on/off programmatically (the blue "shift" on Nokia N900) or access keyboard layout information for currently used localisation, since the standard HTML5 input types seem not to be recognized (and input method hinting / validating works only on native Qt form elements - or does it).
 
Posts: 402 | Thanked: 229 times | Joined on Nov 2009 @ Missouri, USA
#4
What about javascript? something like this

Or overriding QKeyEvent, calling itself as though the Alt event had been pressed.

Pseudocode
Code:
class QMyWebView(QWebView)
    def keyEvent(self, event):
        QWebView.keyEvent(type, modifiers | Qt.AltModifier)
__________________
aspidites | blog | aspidites@inbox.com

Last edited by aspidites; 2010-06-15 at 16:11.
 
Reply


 
Forum Jump


All times are GMT. The time now is 17:00.