[PyQt] Clearing and disabling a QLineEdit causes a cursor to be shown?

Hans-Peter Jansen hpj at urpla.net
Sat Oct 9 14:34:27 BST 2010


On Saturday 09 October 2010, 14:43:19 Nick Gaens wrote:
> Hello everybody,
>
> When trying to "reset" a form, consisting out of some QLineEdits and
> QSpinBoxes, I use this small piece of code:
>
>
> for field in [self.customerDataLayout.itemAtPosition(row, 1) for row
> in xrange(0, self.customerDataLayout.rowCount())]:
>             widget = field.widget()
>             widget.clear()
>             widget.setEnabled(False)
>
>
> The result is that all those QLineEdits and QSpinBoxes are in fact
> 'cleared' and disabled, but the side effect is that some sort of
> vertical line (cursor?) is drawn in each QLineEdit (see the
> attachment for a screenshot of this problem).
>
> Is this normal behavior? How do I disable this vertical line to be
> shown?

Hard to say with some code to experiment with. You might try:
 - try:
       widget.readOnly(True)
   except AttributeError:
       pass
   before widget.setEnabled(False)
 - use a two pass approach, where the loop with the
   widget.setEnabled(False) body is called from a QTimer.SingleShot(0, )
 - a mixture of these

Pete


More information about the PyQt mailing list