Results 1 to 8 of 8

Thread: All QStyleOptionButton in listview sunken when clicking one of them

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2007
    Posts
    244
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    42
    Thanked 8 Times in 8 Posts

    Default Re: All QStyleOptionButton in listview sunken when clicking one of them

    This is my constructor:

    Qt Code:
    1. ItemDelegate::ItemDelegate(QObject *parent) :
    2. {
    3. _state = QStyle::State_Enabled;
    4. }
    To copy to clipboard, switch view to plain text mode 

    Thanks for your patience
    Giuseppe CalÃ

  2. #2
    Join Date
    Aug 2007
    Posts
    244
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    42
    Thanked 8 Times in 8 Posts

    Default Re: All QStyleOptionButton in listview sunken when clicking one of them

    I solved changing approach; I'm not using anymore _state member but int _currRow to track clicked button; here it is a sample code:

    Qt Code:
    1. ItemDelegate::ItemDelegate(QObject *parent) :
    2. {
    3. _currRow = -1;
    4. }
    5.  
    6. void ItemDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
    7. {
    8. if (!index.isValid())
    9. return;
    10.  
    11. QApplication::style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter, 0);
    12.  
    13. ...
    14.  
    15. button.rect = buttonRect;
    16. button.features |= QStyleOptionButton::Flat;
    17.  
    18. if(_currRow == index.row())
    19. button.state = QStyle::State_Sunken | QStyle::State_Enabled;
    20. else
    21. button.state = QStyle::State_Raised | QStyle::State_Enabled;
    22.  
    23. QApplication::style()->drawControl(QStyle::CE_PushButton, &button, painter);
    24. }
    25.  
    26. bool ItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
    27. {
    28. Q_UNUSED(model)
    29.  
    30. if( event->type() != QEvent::MouseButtonPress &&
    31. event->type() != QEvent::MouseButtonRelease ) {
    32. return true;
    33. }
    34.  
    35. if( event->type() == QEvent::MouseButtonPress)
    36. _currRow = index.row();
    37. else
    38. _currRow = -1;
    39.  
    40. ...
    41.  
    42. QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
    43. if( !buttonRect.contains( mouseEvent->pos()) ) {
    44. return true;
    45. }
    46.  
    47. if( event->type() == QEvent::MouseButtonRelease) {
    48. // call slot
    49. }
    50.  
    51. return true;
    52. }
    To copy to clipboard, switch view to plain text mode 

    Thanks ChrisW67 for your time.
    Giuseppe CalÃ

Similar Threads

  1. Adding stylesheet and icon to QStyleOptionButton
    By riarioriu3 in forum Newbie
    Replies: 0
    Last Post: 8th August 2012, 14:12
  2. Clicking on a plot
    By Ronayn in forum Qwt
    Replies: 1
    Last Post: 29th April 2011, 13:59
  3. Clicking on QwtPlot
    By orignihn in forum Qwt
    Replies: 1
    Last Post: 14th April 2011, 16:37
  4. Remove shadow of child widgets? Like a sunken frame...
    By new_voodoo in forum Qt Programming
    Replies: 0
    Last Post: 13th December 2010, 23:31
  5. Clicking Whitespace in a table
    By shooogun in forum Qt Programming
    Replies: 5
    Last Post: 27th March 2008, 06:29

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.