Results 1 to 3 of 3

Thread: QStyledItemDelegate, QStyle::State_MouseOver MAC issues

  1. #1
    Join Date
    Apr 2011
    Posts
    132
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QStyledItemDelegate, QStyle::State_MouseOver MAC issues

    The mouse over does not work on mac. Am I doing it wrong ?

    Qt Code:
    1. QStyleOptionViewItemV4 optionV4 = option;
    2. initStyleOption(&optionV4, index);
    3.  
    4. QStyle *style = optionV4.widget? optionV4.widget->style() : QApplication::style();
    5.  
    6.  
    7.  
    8.  
    9. if (optionV4.state & QStyle::State_MouseOver) {
    10. doc.setDefaultStyleSheet("a {text-decoration: underline; cursor:pointer}");
    11. } else {
    12. doc.setDefaultStyleSheet("a {text-decoration: none;}");
    13. }
    14.  
    15. doc.setHtml(optionV4.text);
    To copy to clipboard, switch view to plain text mode 

    Also looks like the "cursorointer" does not work on all platforms, any ideas ?

  2. #2
    Join Date
    Apr 2011
    Posts
    132
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QStyledItemDelegate, QStyle::State_MouseOver MAC issues

    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 ??


    Qt Code:
    1. void LinkDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
    2. const QModelIndex &index) const
    3. {
    4. QStyleOptionViewItemV4 optionV4 = option;
    5. initStyleOption(&optionV4, index);
    6.  
    7. QStyle *style = optionV4.widget? optionV4.widget->style() : QApplication::style();
    8.  
    9. QTextOption textOption;
    10. textOption.setAlignment(Qt::AlignCenter);
    11.  
    12. doc.setDefaultTextOption(textOption);
    13.  
    14. if (optionV4.state & QStyle::State_MouseOver) {
    15. doc.setDefaultStyleSheet("a {text-decoration: underline; text-align:center;}");
    16. } else {
    17. doc.setDefaultStyleSheet("a {text-decoration: none;text-align:center;}");
    18. }
    19.  
    20. doc.setHtml(optionV4.text);
    21.  
    22. // Painting item without text
    23. optionV4.text = QString();
    24. style->drawControl(QStyle::CE_ItemViewItem, &optionV4, painter);
    25.  
    26. QAbstractTextDocumentLayout::PaintContext ctx;
    27.  
    28. // Highlighting text if item is selected
    29. if (optionV4.state & QStyle::State_Selected)
    30. ctx.palette.setColor(QPalette::Text, optionV4.palette.color(QPalette::Active, QPalette::HighlightedText));
    31.  
    32. QRect textRect = style->subElementRect(QStyle::SE_ItemViewItemText, &optionV4);
    33. painter->save();
    34. painter->translate(textRect.topLeft());
    35. painter->setClipRect(textRect.translated(-textRect.topLeft()));
    36. doc.documentLayout()->draw(painter, ctx);
    37. painter->restore();
    38.  
    39. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by migel; 6th October 2011 at 21:00.

  3. #3
    Join Date
    Nov 2012
    Posts
    1
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows Android

    Default Re: QStyledItemDelegate, QStyle::State_MouseOver MAC issues

    Try setting something like this first:

    widget->setAttribute(Qt::WA_Hover, true);

    Then see if QStyle::State_MouseOver works on Mac.

Similar Threads

  1. QTreeView & QStyledItemDelegate
    By mentalmushroom in forum Qt Programming
    Replies: 0
    Last Post: 29th September 2011, 07:57
  2. Replies: 2
    Last Post: 14th July 2011, 12:28
  3. Custom QStyledItemDelegate
    By Berryblue031 in forum Qt Programming
    Replies: 0
    Last Post: 2nd March 2011, 10:32
  4. QStyledItemDelegate and QStyle::State_MouseOver
    By moti.lahiani in forum Qt Programming
    Replies: 0
    Last Post: 19th January 2011, 06:36
  5. Replies: 0
    Last Post: 11th November 2010, 13:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.