How could I make the QLineEdit UpperCase without using InputMask?
How could I make the QLineEdit UpperCase without using InputMask.
I don't want to use it because when I use it inputMask like ">AAAAAAA" the curser doesn't starts begenning of the line. It start where ever I click in the line.
I need to delegate the lines by using "promote to" with QtDesigner.
Can you please write an example delegate class for QLineEdit
I did it for line in a QTableWidget but not an indepandent QLineEdit
It is Like:
Code:
{
font.
setCapitalization(QFont::AllUppercase);
editor->setFont(font);
return editor;
}
{
QString value
= index.
model()->data
(index, Qt
::DisplayRole).
toString();
QLineEdit *qline
= static_cast<QLineEdit
*>
(editor
);
font.
setCapitalization(QFont::AllUppercase);
editor->setFont(font);
qline->setText(value);
}
{
QLineEdit *qline
= static_cast<QLineEdit
*>
(editor
);
font.
setCapitalization(QFont::AllUppercase);
editor->setFont(font);
model->setData(index, value.toUpper());
}
Re: How could I make the QLineEdit UpperCase without using InputMask?
a little bit tricky, but works fine :cool:
Code:
...
connect(le,
SIGNAL(textEdited
(const QString &)),
SLOT(toUpper(const QString &)));
...
void Test
::toUpper(const QString &text
) {
QLineEdit *le
= qobject_cast<QLineEdit
*>
(sender
());
if (!le)
return;
le->setText(text.toUpper());
}
Re: How could I make the QLineEdit UpperCase without using InputMask?
you can:
* set a QValidator that converts the letters to upper case
* intercept key events and convert to key
* connect to textChanged and change the text again (drawbacks when editing not at the end...)
I suggest you set a QValidator
Re: How could I make the QLineEdit UpperCase without using InputMask?
I found that codes
Code:
pqUpcaseValidator
::pqUpcaseValidator( QWidget* Parent,
const char* Name
){}
QValidator::State pqUpcaseValidator
::validate( QString
& Text , int
& Pos
) const {
Text = Text.upper();
return Acceptable;
}
What kind of document I should write?
is that currect?
Code:
#ifndef MYUPPERLINE_H
#define MYUPPERLINE_H
#include <QtGui>
{
public:
pqUpcaseValidator
::pqUpcaseValidator( QWidget* Parent,
const char* Name
) {}
QValidator::State pqUpcaseValidator
::validate( QString
& Text , int
& Pos
) const {
Text = Text.upper();
return Acceptable;
}
};
and is it enough to promote it by designer?
Re: How could I make the QLineEdit UpperCase without using InputMask?
well, once u have written the validator, u have to call setValidator() for QLineEdit..that should do it. And yes, ur class would be good enough for promoting once u have set the validator for QLineEdit
Re: How could I make the QLineEdit UpperCase without using InputMask?
Quote:
Originally Posted by
spirit
a little bit tricky, but works fine :cool:
Code:
...
connect(le,
SIGNAL(textEdited
(const QString &)),
SLOT(toUpper(const QString &)));
...
void Test
::toUpper(const QString &text
) {
QLineEdit *le
= qobject_cast<QLineEdit
*>
(sender
());
if (!le)
return;
le->setText(text.toUpper());
}
I can't delegate but this solition is OK for now. Thank you all.:D
Re: How could I make the QLineEdit UpperCase without using InputMask?
I got a problem about one of Capital letters.
In Turkish (utf-8, Latin5), alfabet is a litle bit differents from English alfabet.
we have lower case "i" and it's upper case is" İ".
At the same time ;
we have lower case "ı" and upper case "I".
When caps lock off if I hit "ı" or "i" it returns "I" that is wrong the correct is if I hit "i" it must return "İ".:confused:
When caps lock on, it work correct.
I tried: (but nothing chaged)
Code:
void formCari
::toUpper(const QString &text
) {
QLineEdit *SSSSSSS
= qobject_cast<QLineEdit
*>
(sender
());
if (!SSSSSSS)
return;
SSSSSSS->setText(text.toUpper());
}
P.S. if you can not read the letters that I write, I can explain. the upper case of "i" is "I" with top point as the lower one. And all so, lower case of "I" is like "i" but with out point.
Re: How could I make the QLineEdit UpperCase without using InputMask?
you don't seem to actually use that QLocale you created...?
Re: How could I make the QLineEdit UpperCase without using InputMask?
Quote:
Originally Posted by
caduel
you don't seem to actually use that QLocale you created...?
but how I?
Re: How could I make the QLineEdit UpperCase without using InputMask?
Probably with QLocale::setDefault()It would probably be good to set that at startup and not change this (global) setting too often. I am not sure if it will really affect the workings of toUpper. But it is worth a try.
Re: How could I make the QLineEdit UpperCase without using InputMask?
Actually I did it but not changed