[PyQt] Suppress departure from cell in QTableView
John F Sturtz
john at sturtz.org
Fri Feb 22 01:37:08 GMT 2019
Hello again Maurizio.
I attempted a response to your message a few minutes ago, and accidentally sent it before I was finished with it. :-/
Please disregard that one; this is the full response:
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 in this way.
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 normal). This is quite easy to do with a QLabel because it can contain rich text -- e.g.,
setText('foo<span style="font-style: italic;">bar</span>')
This doesn't appear to work for the contents of a QLineEdit widget.
I did find this stackoverflow post regarding styling of text within a QLineEdit:
https://stackoverflow.com/questions/14417333/how-can-i-change-color-of-part-of-the-text-in-qlineedit
But it looks like a lot of messiness ...
/John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20190221/c95749f4/attachment.html>
More information about the PyQt
mailing list