AlphaNumeric input hint

Post Reply
seasoned_geek
Posts: 29
Joined: Thu Jun 11 2020 12:18 pm

AlphaNumeric input hint

Post by seasoned_geek »

It would be nice if we could get an AlphaNumeric input hint. Something that would only allow letters and numbers. No spaces or punctuation. Would not care about upper or lower case.

Code: Select all

    //  TODO:: Really need to get an AlphaNumeric hint added
    destName = QInputDialog::getText(this, "New Theme name", "Name: ", QLineEdit::Normal,
                                     destName, &okFlag, Qt::Dialog, Qt::ImhNone);
Right now I think we have to create our own validator to do such a thing. Be much nicer if the hint could just do that for us.

Yes, I want some cheese for my whine. :P

barbara
Posts: 175
Joined: Sat Apr 04 2015 2:32 am

Re: AlphaNumeric input hint

Post by barbara »

We traced through the code for QInputDialog::getText() and these are hints which are intended to be
processed in the platform plugin. A few of the hints are handled for cocoa but none of them are processed on windows or xcb.

From our research the purpose of QInputMethod (which is the class that handles the hint) was designed to deal with configuring a virtual keyboard. For a desktop application the proper way to constrain input or use a mask is with a validator.

For a line edit you can use QLineEdit::setInputMask() or QLineEdit::setValidator(). Here is a a quick example that will work in CopperSpice.

Code: Select all

// any alpha char, any number
auto regex = new QRegularExpressionValidator( QRegularExpression("[\\d\\l\\u]*") );
lineEdit->setValidator(regex); 
Barbara

Post Reply