I have a series of QButton subclasses between which drag-drop operations can be performed. Each button has text and an icon, which is simply a badge with one or two characters (usually a number):

Qt Code:
  1. QIcon GMScriptCenter::badgeIcon(const QSize &size, const QColor &outlineColor, const QColor &fillColor, const QString &badgeText)
  2. {
  3. QPixmap pixmap(size);
  4. pixmap.fill(Qt::transparent);
  5. QPainter painter(&pixmap);
  6. painter.setRenderHint(QPainter::Antialiasing);
  7.  
  8. painter.setPen(QPen(outlineColor));
  9. int minWH = qMax(qMin(size.width(), size.height()), 1);
  10. QRect rect(QPoint(0, 0), size);
  11. painter.setBrush(QBrush(fillColor)); // commenting either this, or...
  12. painter.drawRoundedRect(rect.adjusted(1, 1, -1, -1), minWH/5, minWH/5); // ...this prevents crash
  13.  
  14. if (!badgeText.isNull()) {
  15. painter.setFont(QFont("Trebuchet MS", size.height()-10));
  16. painter.setPen(QPen(Qt::white));
  17. painter.drawText(rect, badgeText, QTextOption(Qt::AlignCenter));
  18. }
  19.  
  20. return QIcon(pixmap);
  21. }
To copy to clipboard, switch view to plain text mode 

Usually, I can call this function to generate an icon and it works fine. But in one circumstance, it does not. After an accepted "drop", in the dropEvent method of my button subclass, I call:

Qt Code:
  1. this->setIcon(GMScriptCenter::shared().badgeIcon(QSize(this->iconSize()), Qt::darkBlue, QColor(0, 80, 180, 200), "1"));
To copy to clipboard, switch view to plain text mode 

It crashes! And bizarrely, it doesn't crash if I comment out either the setBrush or drawRoundedRect lines. I can generate this badge with just a frame and text and it's fine. It's when I try to use that brush...

What on earth could be happening? Is this a thread-related issue?