Skip to content

Crash if delegate subclass implements displayText #68

Open
@cpinter

Description

@cpinter

This self-contained test helps reproduce the problem:

class PaddingDelegate(qt.QStyledItemDelegate):
  def __init__(self, padding=1, parent=None):
    super(PaddingDelegate, self).__init__(parent)
    self._padding = ' ' * max(1, padding)
  def displayText(self, text, locale):
    return self._padding + text
  def createEditor(self, parent, option, index):
    editor = super().createEditor(parent, option, index)
    margins = editor.textMargins()
    padding = editor.fontMetrics().width(self._padding) + 1
    margins.setLeft(margins.left() + padding)
    editor.setTextMargins(margins)
    return editor

table = qt.QTableWidget()
delegate = PaddingDelegate(3)
table.setItemDelegate(delegate)
table.setRowCount(1)
table.setColumnCount(1)
item = qt.QTableWidgetItem('Test')
table.show()
table.setItem(0,0,item)

The call stack looks like this:

	Qt5Cored.dll!QAtomicOpsBySize<4>::deref<int>(int & _q_value) Line 314	C++
 	Qt5Cored.dll!QBasicAtomicInteger<int>::deref() Line 114	C++
 	Qt5Cored.dll!QVariant::~QVariant() Line 1515	C++
 	PythonQt.dll!PythonQtConv::ConvertPythonToQt(const PythonQtMethodInfo::ParameterInfo & info, _object * obj, bool strict, PythonQtClassInfo * __formal, void * alreadyAllocatedCPPObject, PythonQtArgumentFrame * frame) Line 603	C++
 	PythonQt.dll!PythonQtShell_QStyledItemDelegate::displayText(const QVariant & value0, const QLocale & locale1) Line 814	C++
 	Qt5Widgetsd.dll!QStyledItemDelegate::initStyleOption(QStyleOptionViewItem * option, const QModelIndex & index) Line 348	C++
 	PythonQt.dll!PythonQtShell_QStyledItemDelegate::initStyleOption(QStyleOptionViewItem * option0, const QModelIndex & index1) Line 986	C++
 	Qt5Widgetsd.dll!QStyledItemDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) Line 387	C++
 	PythonQt.dll!PythonQtShell_QStyledItemDelegate::paint(QPainter * painter0, const QStyleOptionViewItem & option1, const QModelIndex & index2) Line 1008	C++
 	Qt5Widgetsd.dll!QTableViewPrivate::drawCell(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) Line 925	C++
 	Qt5Widgetsd.dll!QTableView::paintEvent(QPaintEvent * event) Line 1470	C++

In PythonQtConv::ConvertPythonToQt the crash happens in this part:

    case QMetaType::QString:
       {
         QString str = PyObjGetString(obj, strict, ok);
         if ( ok) {
           PythonQtArgumentFrame_ADD_VARIANT_VALUE_IF_NEEDED(alreadyAllocatedCPPObject, frame, QVariant(str), ptr);
           ptr = (void*)((QVariant*)ptr)->constData();
         }
       }
       break;
     case QMetaType::QStringList:

at the line with ADD_VARIANT_VALUE_IF_NEEDED.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions