Stylesheet en Delegate
Unsolved
Spanish
-
Hola, he creado un QStyledItemDelegate para mostrar una imagen en un QTableView a la cual la tengo aplicada un stylesheet, todo funciona bien a excepción que los items mostrados desde el delegate ya que no muestran el stylesheet asignado a la tabla. ¿Alguien me puede ayudar?
Stylesheet
qApp->setStyleSheet("QHeaderView::section " "{background-color: rgb(255, 255, 255); " "padding: 4px; " "font: 12pt 'Courier New'; " "border-style: none; " "border-bottom: 1px solid; " "border-bottom-color: rgb(160, 208, 235);} " "QTableView::item" "{padding: 4px;" "border-bottom: 1px solid;" "border-bottom-color: rgb(186, 186, 186);}");
El delegate
///.h class ImagenDelegate : public QStyledItemDelegate { Q_OBJECT public: ImagenDelegate(QWidget *parent = 0) : QStyledItemDelegate(parent) {} void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; }; /// .ccp void ImagenDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { if (index.column()==2){ QDir aplication_path; QString value = index.model()->data(index, Qt::EditRole).toString(); QString path_imagen = aplication_path.currentPath() + "/imagenes/productos/" + value; QFileInfo check_file(path_imagen); QStyleOptionButton button; QRect r = option.rect; int x,y,w,h; x = r.left() + r.width() - 57; y = r.top()+4; w = 54; h = 54; button.rect = QRect(x,y,w,h); button.state = QStyle::State_Enabled; button.iconSize = QSize(48,48); if (check_file.exists() && check_file.isFile()){ button.icon = QPixmap(path_imagen); } else { button.icon = QPixmap(":/img/img/logo.png"); } qApp->style()->drawControl(QStyle::CE_PushButton, &button, painter); //qDebug()<<option.widget->styleSheet(); //QApplication::style()->drawControl(QStyle::CE_PushButton, &button, painter); } }
-
Hola @raulgg
Dices que "los items mostrados desde el delegate no les afecta el estilo". O sea, que hay otros en la misma tabla que sí les afecta.¿Has probado aplicando el estilo en el delegate? Supongo que el estilo lo aplicas antes de cargar los datos de la tabla ¿no? No sé si esto podrá afectar a que se apliquen los estilos o no.
Imagino que te has mirado la documentación por si hay algún detalle que afecte a los delegates.
Un saludo