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
Qt: QSS and drawComplexControl()
-
06-10-2022 - |
Domanda
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:
Is it possible for drawComplexControl() to consider the style sheet?
Thanks
Soluzione
Altri suggerimenti
I believe that you need to use dirty hacks with casting style() to private QStyleSheetStyle
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow