Results 1 to 11 of 11

Thread: selection in QLineEdit

  1. #1
    Join Date
    Apr 2007
    Location
    Moscow
    Posts
    6
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default selection in QLineEdit

    hello, everybody!

    Now I look to QT examples, like Calculator where we have QLineEdit as display widget.
    I have just tried some things with 'calculator' code, GUI code.

    I will disable text selection in display but how?
    I know we can disable selection in view's (like QTabView or QTreeView)
    but how to do it for QLineEdit?

    setFocus(NoFocus) ?

    or some other things like:
    1. set in palette highlight color same as background color.
    2. if receive signal 'selectionChange' set selection back to 0

    May be there are another solutions for this?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: selection in QLineEdit

    How about just setting the readOnly property to true?

  3. #3
    Join Date
    Apr 2007
    Location
    Moscow
    Posts
    6
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: selection in QLineEdit

    yes, I've tried setReadOnly(true) but it do nothing to difference.
    readOnly property just disable user input to LineEdit, but it don't disable text copy or selection.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: selection in QLineEdit

    Connect to selectionChanged() signal and call deselect(). Or just use QLabel instead of QLineEdit. What's the point of using the line edit if you want to disable all its functionality?

  5. #5
    Join Date
    Apr 2007
    Location
    Moscow
    Posts
    6
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: selection in QLineEdit

    I want to disable only text selection in QLineEdit not other!
    thank you!

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: selection in QLineEdit

    Not other what?

  7. #7
    Join Date
    Apr 2007
    Location
    Moscow
    Posts
    6
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: selection in QLineEdit

    thank you. QLabel is good class for replace QLineEdit if you want only display value.
    but main question was how to disable text selection in QLineEdit, anything else.

  8. #8
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: selection in QLineEdit

    No easy way of removing the selection in a line edit.
    But what about using a single line QTextEdit and setting the text interaction flags to no interaction?

  9. #9
    Join Date
    Apr 2007
    Location
    Moscow
    Posts
    6
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: selection in QLineEdit

    QLCDNumber = good class for calculator (style like Citizen calc)

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: selection in QLineEdit

    Why would you want to allow input but disallow selection? Anyway did you try the combination of signals-slots I suggested earlier?

  11. #11
    Join Date
    Apr 2007
    Location
    Moscow
    Posts
    6
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: selection in QLineEdit

    yes, thank you.
    order of goodies:
    1. eventFilter(); for events like MouseButtonPress, Release and Move return true;
    2. use setDisabled + catch input in parent widget, because when lineedit disabled it would not receive events like keyPress, keyRelease
    3. use signal changeSelection and set text selection in slot to zero
    4. use QLCDNumber
    5. use QLabel

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.