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:
{
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());
}
QWidget *AlternatifDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QLocale::setDefault(QLocale(QLocale::Turkish, QLocale::Turkey));
QLineEdit *editor = new QLineEdit(parent);
QFont font;
font.setCapitalization(QFont::AllUppercase);
editor->setFont(font);
return editor;
}
void AlternatifDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
QLocale turkish(QLocale::Turkish);
QString value = index.model()->data(index, Qt::DisplayRole).toString();
QLineEdit *qline = static_cast<QLineEdit*>(editor);
QFont font;
font.setCapitalization(QFont::AllUppercase);
editor->setFont(font);
qline->setText(value);
}
void AlternatifDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const
{
QLocale turkish(QLocale::Turkish);
QLineEdit *qline = static_cast<QLineEdit*>(editor);
QFont font;
font.setCapitalization(QFont::AllUppercase);
editor->setFont(font);
QString value = qline->text();
model->setData(index, value.toUpper());
}
To copy to clipboard, switch view to plain text mode
Bookmarks