<div id="__MailbirdStyleContent" style="font-size: 12pt;font-family: Candara;color: #000000"><span style="color: #366092">
Wow! Thank you so much for all this information. In spite of the time I have spent with PyQt, it is clear I still have much to learn. :-/</span><blockquote class="history_container" type="cite" style="border-left-style: solid;border-width: 1px;margin-top: 20px;margin-left: 0px;padding-left: 10px;min-width: 500px"><div style="font-family:Arial,Helvetica,sans-serif"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div class="gmail_quote"><div><span style="font-size: 12pt;line-height: 1.5">Well, </span><span style="font-family: monospace, monospace">closeEditor</span><span style="font-size: 12pt;line-height: 1.5"> is a </span><b style="font-size: 12pt;line-height: 1.5">signal</b><span style="font-size: 12pt;line-height: 1.5"> in delegates, which is automatically connected to the </span><span style="font-family: monospace, monospace">closeEditor</span><span style="font-size: 12pt;line-height: 1.5"> </span><i style="font-size: 12pt;line-height: 1.5"><b>slot</b></i><span style="font-size: 12pt;line-height: 1.5"> of the item view.</span></div></div></div></div></div></div></div></div></div></div></div></div></div></div></blockquote><div><span style="font-size: 12pt;color: rgb(0, 0, 0)"><span style="color: rgb(59, 89, 152);">Doh! The documentation for <span style="font-family: Courier New">QAbstractItemDelegate</span> clearly says <span style="font-family: Courier New">closeEditor</span> is a signal. This was just a stupid oversight on my part. [:headslap:]<br></span><br></span></div><blockquote class="history_container" type="cite" style="border-left-style: solid;border-width: 1px;margin-top: 20px;margin-left: 0px;padding-left: 10px;min-width: 500px"><div style="font-family:Arial,Helvetica,sans-serif"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div class="gmail_quote"><div><span style="font-size: 12pt;line-height: 1.5"></span></div><div><span style="font-size: 12pt;line-height: 1.5">A much more "elegant" way to do so would be to request the actual view from the parent argument of createEditor(); keep in mind, though, that the parent of the editor is the viewport of the view (since an item view is a QAbstractScrollArea and its contents are in an embedded "scrollable" QWidget), so the reference to the view is the parent() of the parent argument of createEditor() method, actually.</span></div></div></div></div></div></div></div></div></div></div></div></div></div></div></blockquote><div><span style="font-size: 12pt;font-family: Candara;color: #000000"><b><span style="color: #3B5998"></span></b><span style="color: #3B5998">This is great! I was looking for a way to get a reference to the view from the delegate, but I hadn't been able to find one. Didn't look quite hard enough ...<br></span><br></span></div><blockquote class="history_container" type="cite" style="border-left-style: solid;border-width: 1px;margin-top: 20px;margin-left: 0px;padding-left: 10px;min-width: 500px"><div style="font-family:Arial,Helvetica,sans-serif"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div class="gmail_quote"><div><span style="font-size: 12pt;line-height: 1.5"></span></div><div><span style="font-size: 12pt;line-height: 1.5">Luckily enough, Qt's implementation correctly handles QKeyEvents of delegates and views in the right "levels". Tab navigation and return/escape keys are catched by the view, so you can take care of everything in the closeEditor() slot.</span></div></div></div></div></div></div></div></div></div></div></div></div></div></div></blockquote><div><span style="font-size: 12pt;color: rgb(0, 0, 0)"><span style="color: rgb(59, 89, 152);">With your help, and after a bit more messing around, I have a version which seems nicely concise and reliable. I validate input inside <span style="font-family: Courier New">setModelData()</span>, and call <span style="font-family: Courier New">model.setData()</span> if valid, but inhibit departure from the cell if not. Then from <span style="font-family: Courier New">closeEditor()</span>, I use the same validation function, and close the editor if valid, but leave it open if not.</span></span></div><div><span style="font-size: 12pt;color: rgb(0, 0, 0)"><span style="color: rgb(59, 89, 152);"><br></span></span></div><div><span style="font-size: 12pt;color: rgb(0, 0, 0)"><span style="color: rgb(59, 89, 152);">It seems to work for any method of cell departure, without explicitly catching mouse clicks or keystrokes.</span></span></div><div><span style="font-size: 12pt;color: rgb(0, 0, 0)"><span style="color: rgb(59, 89, 152);"><br></span></span></div><div><span style="font-size: 12pt;color: rgb(0, 0, 0)"><span style="color: rgb(59, 89, 152);">I've attached it in case you're interested. (For test purposes, the validation function calls any string of digits valid, and anything else not).</span><br></span></div><div><span style="font-size: 12pt;color: rgb(0, 0, 0)"><span style="color: rgb(59, 89, 152);"><br></span></span></div><blockquote class="history_container" type="cite" style="border-left-style: solid;border-width: 1px;margin-top: 20px;margin-left: 0px;padding-left: 10px;min-width: 500px"><div style="font-family:Arial,Helvetica,sans-serif"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div class="gmail_quote"><div><span style="font-size: 12pt;line-height: 1.5"></span></div><div><span style="font-size: 12pt;line-height: 1.5">PS: in your code, you've been using model.setData() inside the setEditorData() method of the itemDelegate, which not only doesn't makes not much sense, but might also result in an infinite recursion.</span></div></div></div></div></div></div></div></div></div></div></div></div></div></div></blockquote><div><span style="color: rgb(59, 89, 152);">This is a fallout of the following peculiar fact: My actual intention is to use a <span style="font-family: Courier New">QLabel</span> as the delegate editor widget, and not a <span style="font-family: Courier New">QLineEdit</span>. I know that seems weird, but it gives me more precise control over the editing that occurs. (Basically, I respond to keyboard input, modify the <span style="font-family: Courier New">QLabel</span>'s text, then redisplay it. In the attached example, I changed the <span style="font-family: Courier New">QLineEdit</span> back to a <span style="font-family: Courier New">QLabel</span>, so you can see what I mean).</span></div><div><span style="color: rgb(59, 89, 152);"><br></span></div><div><span style="color: rgb(59, 89, 152);">So the reason I called <span style="font-family: Courier New">model.setData()</span> (with a null value) inside <span style="font-family: Courier New">setEditorData()</span> was to clear out the previous cell contents. If I didn't, the previous cell contents and the <span style="font-family: Courier New">QLabel</span> text would both display, overlapped with one another.</span></div><div><span style="color: rgb(59, 89, 152);"><br></span></div><div><span style="color: rgb(59, 89, 152);">It turns out all I needed to do was give the <span style="font-family: Courier New">QLabel</span> an opaque background, so it just covers up the previous cell contents. :-)</span></div><div><span style="color: rgb(59, 89, 152);"><br></span></div><div><span style="color: rgb(59, 89, 152);">------</span></div><div><span style="color: rgb(59, 89, 152);"><br></span></div><div><span style="color: rgb(59, 89, 152);">There is one thing in the current version that still puzzles me: In the most recent round of messing around, I decided to subclass <span style="font-family: Courier New">QLabel</span>, and then use an object of the subclass as the editor widget rather than an actual <span style="font-family: Courier New">QLabel</span>. And I decided to move keypress handling from <span style="font-family: Courier New">eventFilter()</span> in the delegate to <span style="font-family: Courier New">keyPressEvent()</span> in the editor widget subclass. In the process, it seemed to change the way Tab is handled.</span></div><div><span style="color: rgb(59, 89, 152);"><br></span></div><div><span style="color: rgb(59, 89, 152);">If you run the code as I attached it, keyboard input is handled by the delegate's <span style="font-family: Courier New">eventFilter()</span> method. It doesn't <i>do</i> anything with the Tab character. But if you hit Tab while editing, it closes the editor, moves to the next cell, and that cell is <i>not</i> opened for editing.</span></div><div><span style="color: rgb(59, 89, 152);"><br></span></div><div><span style="color: rgb(59, 89, 152);">If you comment out the <span style="font-family: Courier New">eventFilter()</span> method (lines 59-81), and enable <span style="font-family: Courier New">keyPressEvent()</span> in the editor widget subclass (lines 92-112), then tabbing out of an edit field closes the editor, and opens the next field up for editing.</span></div><div><span style="color: rgb(59, 89, 152);"><br></span></div><div><span style="color: rgb(59, 89, 152);">The latter is the default behavior for the Tab character, I believe. But the former is actually what I want. So it works the way I'd wish when I handle keyboard input in the delegate. But I'm not doing anything with Tab character in either case, so it seems strange to me that in one case I'm getting one behavior, and in the other case another.</span></div><div><span style="color: rgb(59, 89, 152);"><br></span></div><div><span style="color: rgb(59, 89, 152);"><br></span></div><div><span style="color: rgb(59, 89, 152);">In any event, I think I'm making progress. Thanks again for the help! I really appreciate it.</span></div><div><span style="color: rgb(59, 89, 152);"><br></span></div><div><span style="color: rgb(59, 89, 152);">/John</span></div><blockquote class="history_container" type="cite" style="border-left-style: solid;border-width: 1px;margin-top: 20px;margin-left: 0px;padding-left: 10px;min-width: 500px"><div style="font-family:Arial,Helvetica,sans-serif"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div class="gmail_quote"><div><span style="font-size: 12pt;line-height: 1.5"></span></div></div></div></div></div></div></div></div></div></div></div></div></div>
</div></blockquote></div>