I have an odd problem.
I am using QStyle
's drawControl()
to draw a progress bar in a custom QStyledItemDelegate
's paint().
Now the application crashes, when I try to open a QMessageBox
with either show()
or exec()
or whatever.
I am quite sure, that this is not my fault and that it is exactly this combination.
I wrote a quite minimal example project, that shows the problem.
This is the delegate's paint()
:
void ItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QStyleOptionProgressBar progressBarOption;
progressBarOption.rect = option.rect;
progressBarOption.minimum = 0;
progressBarOption.maximum = 100;
progressBarOption.progress = index.data().toInt();
// This line crashes a QMessageBox. CE_ProgressBarContents and CE_ProgressBar lead to a crash.
// All other values of QStyle::CE_*** work fine.
// drawComplexControl has no problem either.
QApplication::style()->drawControl(QStyle::CE_ProgressBarContents, &progressBarOption, painter);
}
If I set this delegate on a QTreeView (which of course has items) and open a QMessageBox, the application crashes.
The example project can be found on my GitHub.
I also opened a discussion on qtcentre with additional information.
I am using Qt 5.0.1 on Mac OS X 10.8.2. Is this a Qt bug? How would you work around it?