[PyQt] Object lifetime issues with dialogs, called from QStyledItemDelegate editors

Hans-Peter Jansen hpj at urpla.net
Sat Apr 8 21:06:09 BST 2017


Hi,

I'm suffering from strange behavior related to object lifetime issues, when 
modal dialogs are called from QStyledItemDelegate editors, and posted these 
issues here:

http://stackoverflow.com/questions/43298605/strange-behavior-of-qcolordialog-when-called-from-qstyleditemdelegate-subclass

http://stackoverflow.com/questions/43299616/calling-qcolordialog-triggered-from-qstyleditemdelegate-editor-results-in-crash

When executing the itemdelegate.py script, double clicking on a color item 
displays the standard QColorDialog. The dialog will close immediately, if the 
dialog is moved(!). OTOH, selecting an arbitrary color beforehand, the dialog 
behaves correctly.. 

The mplexitemdelegate.py script crashes, when closing the QColorDialog, after 
being called from a QTableView subclass, triggered from a signal. 

When started, various editors for different types appear in the second column. 
The color editors open a QComboBox with various predefined colors. The last 
item triggers a signal in the QTableView, that calls QColorDialog.getColor(). 

Earlier versions attempted to open the QColorDialog from the 
QStyledItemDelegate editor directly, similar to the code in the first issue, 
with the same result (segfault), unlike that issue, where the QColorDialog 
behaves strangely.

One could observe, that opening the dialog triggers a window context change, 
which probably results in destructing the delegate editor of the table view. 
Therefore I implemented the selectColorDialog signal, that operates completely 
independent from the delegate editor. The gdb backtrace points to some 
QAccessible methods, triggered from the QComboBox, but I cannot see the 
relation here. 

Other attempts to cope with this issue used subclassed QComboBoxes with 
subclassed QLineEdits, catching and ignoring any leave, hide and close events 
during the lifetime of the color dialog, but they failed in similar ways.
Also executing other dialogs from within this setting show the same behavior, 
that I would like to understand.

Any idea anybody, what's going wrong here? It might be a Qt5 issue, though.

Thanks in advance,
Pete

Environment:
Python: 3.4.5
Sip: 4.19.2
Qt5: 5.8.0
PyQt5: 5.8.2
Linux: openSUSE/KDE4
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mplexitemdelegates.py
Type: text/x-python
Size: 12804 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20170408/0de45a8e/attachment.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: itemdelegate.py
Type: text/x-python
Size: 3546 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20170408/0de45a8e/attachment-0001.py>


More information about the PyQt mailing list