Really no solutions ??
this is my full func. When I mouse over nothing happen, but when I use the scroll on my mouse then is highlighted.
Also can't get the cursor changing working on all platforms. any ideas ??
{
QStyleOptionViewItemV4 optionV4 = option;
initStyleOption(&optionV4, index);
textOption.setAlignment(Qt::AlignCenter);
doc.setDefaultTextOption(textOption);
if (optionV4.
state & QStyle::State_MouseOver) { doc.setDefaultStyleSheet("a {text-decoration: underline; text-align:center;}");
} else {
doc.setDefaultStyleSheet("a {text-decoration: none;text-align:center;}");
}
doc.setHtml(optionV4.text);
// Painting item without text
style
->drawControl
(QStyle::CE_ItemViewItem,
&optionV4, painter
);
// Highlighting text if item is selected
if (optionV4.
state & QStyle::State_Selected)
QRect textRect
= style
->subElementRect
(QStyle::SE_ItemViewItemText,
&optionV4
);
painter->save();
painter->translate(textRect.topLeft());
painter->setClipRect(textRect.translated(-textRect.topLeft()));
doc.documentLayout()->draw(painter, ctx);
painter->restore();
}
void LinkDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
QStyleOptionViewItemV4 optionV4 = option;
initStyleOption(&optionV4, index);
QStyle *style = optionV4.widget? optionV4.widget->style() : QApplication::style();
QTextDocument doc;
QTextOption textOption;
textOption.setAlignment(Qt::AlignCenter);
doc.setDefaultTextOption(textOption);
if (optionV4.state & QStyle::State_MouseOver) {
doc.setDefaultStyleSheet("a {text-decoration: underline; text-align:center;}");
} else {
doc.setDefaultStyleSheet("a {text-decoration: none;text-align:center;}");
}
doc.setHtml(optionV4.text);
// Painting item without text
optionV4.text = QString();
style->drawControl(QStyle::CE_ItemViewItem, &optionV4, painter);
QAbstractTextDocumentLayout::PaintContext ctx;
// Highlighting text if item is selected
if (optionV4.state & QStyle::State_Selected)
ctx.palette.setColor(QPalette::Text, optionV4.palette.color(QPalette::Active, QPalette::HighlightedText));
QRect textRect = style->subElementRect(QStyle::SE_ItemViewItemText, &optionV4);
painter->save();
painter->translate(textRect.topLeft());
painter->setClipRect(textRect.translated(-textRect.topLeft()));
doc.documentLayout()->draw(painter, ctx);
painter->restore();
}
To copy to clipboard, switch view to plain text mode
Bookmarks