Qt Centre Forum >
Qt >
Newbie > setInputMask prevent the use of spaces and avoid the sense that something's written
View Full Version : setInputMask prevent the use of spaces and avoid the sense that something's written
hakermania
21st May 2011, 14:31
Hello.
I have a lineedit and I have set its input mask to nnnnnn (numbers+letters) but I have two major problems:
1) I don't want when I click to the lineedit the cursor to go to the end(it goes to the X position where X is the number of the 'nnnn' I have set to the input mask), as there is something written to the lineedit, while it isn't.
2) I want also to prevent the user from inputting spaces, is this possible?
tinysoft
22nd May 2011, 16:39
1) I don't want when I click to the lineedit the cursor to go to the end(it goes to the X position where X is the number of the 'nnnn' I have set to the input mask), as there is something written to the lineedit, while it isn't.
use :
ui->lineEdit->setCursorPosition(x);
where x is the position where you want the cursor to be.
2) I want also to prevent the user from inputting spaces,
use the validator :
QRegExpValidator *noSpaceValidator=new QRegExpValidator(QRegExp("^[A-Za-z0-9]+"),ui->lineEdit);
ui->lineEdit->setValidator(noSpaceValidator);
hakermania
23rd May 2011, 20:06
I'd like to use this but the is not a slot that says on_lineedit_focused/clicked
ui->lineEdit->setCursorPosition(x);
ChrisW67
23rd May 2011, 23:25
Take a look at QWidget::focusInEvent() and related event handlers.
tinysoft
24th May 2011, 10:18
I'd like to use this but the is not a slot that says on_lineedit_focused/clicked
ui->lineEdit->setCursorPosition(x);
this should do the trick :
connect(ui->lineEdit,SIGNAL(editingFinished()),this ,SLOT(editFinshied()));
void MainWindow::setCursor()
{
ui->lineEdit->setCursorPosition(3);
disconnect(ui->lineEdit,SIGNAL(selectionChanged()),this ,SLOT(setCursor()));
}
void MainWindow::editFinshied()
{
ui->lineEdit->selectAll();
connect(ui->lineEdit,SIGNAL(selectionChanged()),this ,SLOT(setCursor()));
}
good luck !
wysota
24th May 2011, 11:36
Hello.
I have a lineedit and I have set its input mask to nnnnnn (numbers+letters) but I have two major problems:
1) I don't want when I click to the lineedit the cursor to go to the end(it goes to the X position where X is the number of the 'nnnn' I have set to the input mask), as there is something written to the lineedit, while it isn't.
2) I want also to prevent the user from inputting spaces, is this possible?
Use a validator instead of an input mask.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.