Results 1 to 11 of 11

Thread: How could I make the QLineEdit UpperCase without using InputMask?

  1. #1
    Join Date
    Sep 2007
    Location
    Ankara TURKEY
    Posts
    32
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Red face 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:

    Qt Code:
    1. QWidget *AlternatifDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
    2. {
    3. QLocale::setDefault(QLocale(QLocale::Turkish, QLocale::Turkey));
    4. QLineEdit *editor = new QLineEdit(parent);
    5. QFont font;
    6. font.setCapitalization(QFont::AllUppercase);
    7. editor->setFont(font);
    8. return editor;
    9. }
    10. void AlternatifDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
    11. {
    12. QLocale turkish(QLocale::Turkish);
    13. QString value = index.model()->data(index, Qt::DisplayRole).toString();
    14. QLineEdit *qline = static_cast<QLineEdit*>(editor);
    15. QFont font;
    16. font.setCapitalization(QFont::AllUppercase);
    17. editor->setFont(font);
    18. qline->setText(value);
    19. }
    20. void AlternatifDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
    21. const QModelIndex &index) const
    22. {
    23. QLocale turkish(QLocale::Turkish);
    24. QLineEdit *qline = static_cast<QLineEdit*>(editor);
    25. QFont font;
    26. font.setCapitalization(QFont::AllUppercase);
    27. editor->setFont(font);
    28. QString value = qline->text();
    29. model->setData(index, value.toUpper());
    30. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by uygar; 11th February 2009 at 10:55.

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How could I make the QLineEdit UpperCase without using InputMask?

    a little bit tricky, but works fine
    Qt Code:
    1. ...
    2. connect(le, SIGNAL(textEdited(const QString &)), SLOT(toUpper(const QString &)));
    3. ...
    4. void Test::toUpper(const QString &text)
    5. {
    6. QLineEdit *le = qobject_cast<QLineEdit *>(sender());
    7. if (!le)
    8. return;
    9. le->setText(text.toUpper());
    10. }
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. The following 2 users say thank you to spirit for this useful post:

    Qtonimo (6th August 2012), waynew (10th January 2010)

  4. #3
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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

  5. #4
    Join Date
    Sep 2007
    Location
    Ankara TURKEY
    Posts
    32
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: How could I make the QLineEdit UpperCase without using InputMask?

    I found that codes

    Qt Code:
    1. pqUpcaseValidator::pqUpcaseValidator( QWidget* Parent, const char* Name )
    2. : QValidator( Parent, Name )
    3. {}
    4.  
    5. QValidator::State pqUpcaseValidator::validate( QString& Text , int& Pos ) const
    6. {
    7. Text = Text.upper();
    8. return Acceptable;
    9. }
    To copy to clipboard, switch view to plain text mode 

    What kind of document I should write?
    is that currect?

    Qt Code:
    1. #ifndef MYUPPERLINE_H
    2. #define MYUPPERLINE_H
    3. #include <QtGui>
    4. class MyUpperLine2 : public QLineEdit
    5. {
    6. public:
    7. MyUpperLine2(QWidget* parent = 0):QLineEdit(parent) { }
    8.  
    9. pqUpcaseValidator::pqUpcaseValidator( QWidget* Parent, const char* Name )
    10. : QValidator( Parent, Name )
    11. {}
    12.  
    13. QValidator::State pqUpcaseValidator::validate( QString& Text , int& Pos ) const
    14. {
    15. Text = Text.upper();
    16. return Acceptable;
    17. }
    18. };
    To copy to clipboard, switch view to plain text mode 
    and is it enough to promote it by designer?

  6. #5
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default 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

  7. #6
    Join Date
    Sep 2007
    Location
    Ankara TURKEY
    Posts
    32
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Re: How could I make the QLineEdit UpperCase without using InputMask?

    Quote Originally Posted by spirit View Post
    a little bit tricky, but works fine
    Qt Code:
    1. ...
    2. connect(le, SIGNAL(textEdited(const QString &)), SLOT(toUpper(const QString &)));
    3. ...
    4. void Test::toUpper(const QString &text)
    5. {
    6. QLineEdit *le = qobject_cast<QLineEdit *>(sender());
    7. if (!le)
    8. return;
    9. le->setText(text.toUpper());
    10. }
    To copy to clipboard, switch view to plain text mode 
    I can't delegate but this solition is OK for now. Thank you all.

  8. #7
    Join Date
    Sep 2007
    Location
    Ankara TURKEY
    Posts
    32
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question 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 "İ".
    When caps lock on, it work correct.

    I tried: (but nothing chaged)
    Qt Code:
    1. void formCari::toUpper(const QString &text)
    2. {
    3. QLocale turkish(QLocale::Turkish);
    4. QLineEdit *SSSSSSS = qobject_cast<QLineEdit *>(sender());
    5. if (!SSSSSSS)
    6. return;
    7. SSSSSSS->setText(text.toUpper());
    8. }
    To copy to clipboard, switch view to plain text mode 

    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.

  9. #8
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How could I make the QLineEdit UpperCase without using InputMask?

    you don't seem to actually use that QLocale you created...?

  10. #9
    Join Date
    Sep 2007
    Location
    Ankara TURKEY
    Posts
    32
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How could I make the QLineEdit UpperCase without using InputMask?

    Quote Originally Posted by caduel View Post
    you don't seem to actually use that QLocale you created...?
    but how I?

  11. #10
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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.

  12. #11
    Join Date
    Sep 2007
    Location
    Ankara TURKEY
    Posts
    32
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy Re: How could I make the QLineEdit UpperCase without using InputMask?

    Actually I did it but not changed

Similar Threads

  1. how to make system calls to be displayed in QLineEdit
    By wagmare in forum Qt Programming
    Replies: 2
    Last Post: 10th November 2008, 06:08
  2. how to make the QLineEdit uneditable by user
    By wagmare in forum Qt Programming
    Replies: 2
    Last Post: 7th November 2008, 10:20
  3. Pointer Question related to QLineEdit
    By ChrisReath in forum Qt Programming
    Replies: 1
    Last Post: 23rd May 2008, 16:13
  4. QValidator, regular expressions and QLineEdit
    By hvengel in forum Qt Programming
    Replies: 1
    Last Post: 8th August 2007, 02:25
  5. Compiling with Qmake/Make
    By VireX in forum Newbie
    Replies: 25
    Last Post: 22nd February 2007, 06:57

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.