Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt: QSS and drawComplexControl()

I have a QDialog containing a QTableView, along with a custom delegate showing a QComboBox for enum types. When the row is not selected, I still want the QComboBox to be visible (I would like to avoid using QTableView::openPersistentEditor()). To do so, the custom delegate forwards the paint event to the following method:

QStyleOptionViewItem &option) const
{
    painter->save();

    QStyleOptionComboBox comboBoxOption;
    comboBoxOption.rect = option.rect;
    comboBoxOption.state = option.state;
    comboBoxOption.state |= QStyle::State_Enabled;
    comboBoxOption.editable = false;
    comboBoxOption.currentText = enumInfo.valueToKey(curValue);

    // The cast is successful, and srcWidget is the QTableView
    QWidget *srcWidget = qobject_cast<QWidget *>(option.styleObject);

    // style->metaObject()->className() = QStyleSheetStyle
    QStyle *style = srcWidget ? srcWidget->style() : QApplication::style();

    // However, the QSS is ignored here (while srcWidget->styleSheet() correctly
    // returns the style I've set in Qt Designer)
    style->drawComplexControl(QStyle::CC_ComboBox, &comboBoxOption, painter, srcWidget);
    style->drawControl(QStyle::CE_ComboBoxLabel, &comboBoxOption, painter, srcWidget);

    painter->restore();
}

The problem is that I’ve styled the combo box control using QSS, but drawComplexControl() seems to ignore that, despite using the QTableView’s style. Here’s a screenshot:

Application screenshot

Is it possible for drawComplexControl() to consider the style sheet?

Thanks

like image 869
XDnl Avatar asked Dec 05 '25 10:12

XDnl


1 Answers

I think that the only way is to grab widget with QPixmap::grabWidget(). And to use this image in delegate. Seems, that it is not possible to do because of QSS limitation

like image 188
Dmitry Sazonov Avatar answered Dec 08 '25 01:12

Dmitry Sazonov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!