View Full Version : QStyledItemDelegate, QStyle::State_MouseOver MAC issues
migel
4th October 2011, 15:28
The mouse over does not work on mac. Am I doing it wrong ?
QStyleOptionViewItemV4 optionV4 = option;
initStyleOption(&optionV4, index);
QStyle *style = optionV4.widget? optionV4.widget->style() : QApplication::style();
QTextDocument doc;
if (optionV4.state & QStyle::State_MouseOver) {
doc.setDefaultStyleSheet("a {text-decoration: underline; cursor:pointer}");
} else {
doc.setDefaultStyleSheet("a {text-decoration: none;}");
}
doc.setHtml(optionV4.text);
Also looks like the "cursor:pointer" does not work on all platforms, any ideas ?
migel
6th October 2011, 20:42
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 ??
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();
}
leonardo
30th November 2012, 01:48
Try setting something like this first:
widget->setAttribute(Qt::WA_Hover, true);
Then see if QStyle::State_MouseOver works on Mac.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.