[PyQt] Suppress departure from cell in QTableView

John F Sturtz john at sturtz.org
Fri Feb 22 01:24:29 GMT 2019


On 2/20/2019 6:21:15 PM, Maurizio Berti <maurizio.berti at gmail.com> wrote:

This is a fallout of the following peculiar fact:  My actual intention is to use a QLabel as the delegate editor widget, and not a QLineEdit.  I know that seems weird, but it gives me more precise control over the editing that occurs.  

I'm not quite sure I'm following you on that.
I think I can understand your "precise control" needs, but if you can better explain what your needs are, we might help with that.
Using a QLabel for editing is not suggested, not only because it's not its purpose, but also because it doesn't provide sufficient editing cababilities and aidings, from both programming and UX perspectives (and I'm usually mostly focused on the latter).
Let me explain on that.
A label doesn't show the editing cursor (you might object that for simple editings it doesn't matter that much, but knowing where you're typing is a huge feedback) and it doesn't provide any selection nor clipboard implementation. From the user point of view that's not good, as its usage is not intuitive: while the user can "learn" how it works from its behavior, it's usage doesn't justify the change of behavior between similar and common [table/editing] user interfaces.
This is a surprisingly hot-button issue!  I posted a question to stackoverflow that involved this issue, and someone grilled me quite extensively on my use of QLabel for this.

It may be that I could make it work fine using a QLineEdit.  I haven't played with it much, and I probably should.  There are two things I am doing with cell input that I think would be complicated using a QLineEdit:
* Validating cell input character by character.  Each column in the table view has regular expression validation.  I catch a character when it is typed, determine what the cell contents would be with that character added, and disallow that input right at that moment if it would be invalid.
(I think this might be workable with a QLineEdit; I haven't messed with it ...)
* There are cases where I want to have different text style for different parts of the cell contents (for example, some part of the text in Italic and the rest not).
This is quite easy to do with a QLabel because it can contain rich text (e.g.,'foo<span style="font-style: italic;">bar</span>').  This doesn't appear to work for the contents of a QLineEdit widget.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20190221/5047766c/attachment-0001.html>


More information about the PyQt mailing list