PDA

View Full Version : selection in QLineEdit



spigel
16th May 2007, 14:08
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?

wysota
16th May 2007, 14:36
How about just setting the readOnly property to true?

spigel
16th May 2007, 15:03
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.

wysota
16th May 2007, 15:29
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?

spigel
16th May 2007, 16:02
I want to disable only text selection in QLineEdit not other!
thank you!

wysota
16th May 2007, 18:29
Not other what?

spigel
17th May 2007, 06:59
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.

marcel
17th May 2007, 07:30
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?

spigel
17th May 2007, 08:43
QLCDNumber = good class for calculator (style like Citizen calc)

wysota
17th May 2007, 10:24
Why would you want to allow input but disallow selection? Anyway did you try the combination of signals-slots I suggested earlier?

spigel
17th May 2007, 10:43
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