Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash if delegate subclass implements displayText #68

Open
cpinter opened this issue Nov 14, 2019 · 6 comments
Open

Crash if delegate subclass implements displayText #68

cpinter opened this issue Nov 14, 2019 · 6 comments

Comments

@cpinter
Copy link
Member

cpinter commented Nov 14, 2019

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.

@pieper
Copy link
Member

pieper commented Nov 14, 2019

Wouldn't it make more sense to file this on https://github.com/mevislab/pythonqt/ ? Or is this specific to the CTK fork?

@cpinter
Copy link
Member Author

cpinter commented Nov 14, 2019

Probably not specific to this fork, although I haven't tried. I'll file it there then and we'll see

@cpinter
Copy link
Member Author

cpinter commented Nov 14, 2019

It's just that repository does not need to be used. It has one closed issue and no open ones, and here it seems to be active. Thoughts?

@pieper
Copy link
Member

pieper commented Nov 14, 2019

The upstream pythonqt repo is new (used to be on sourceforge) but Florian is responsive so I think it's good to make him aware. There's not much activity because it's pretty stable.

@jcfr
Copy link
Member

jcfr commented Nov 14, 2019

The version of PythonQt used in Slicer is based of a recent PythonQt (see below) and is missing only one commit. See https://github.com/MeVisLab/pythonqt/commits/master

Supported Qt version 5
Branch patched-9
Base PythonQt revision MeVisLab/pythonqt@c07f09fd

@jcfr
Copy link
Member

jcfr commented Nov 14, 2019

May be worth cherry-picking the missing commit (MeVisLab/pythonqt@963b667) locally and see if still crashes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants