Results 1 to 3 of 3

Thread: qpushbutton delegate

  1. #1
    Join Date
    Nov 2012
    Posts
    38
    Thanks
    3

    Default qpushbutton delegate

    hello .
    I wish create a button delegate(with a qpushbutton widget) that is drawed "On" normaly ,and drawed pushed when is clicked.
    i found this on this forum :
    Qt Code:
    1. void MyDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
    2. {
    3. QStyledItemDelegate::paint(painter, option, index);
    4. if (!index.isValid() || index.column() != ButtonColumn) {
    5. return;
    6. }
    7.  
    8. State s = (State)(index.data(Qt::UserRole).toInt());
    9. if (s == Hovered)
    10. opt.state |= QStyle::State_MouseOver;
    11. if (s == Pressed)
    12. opt.state |= QStyle::State_Sunken;
    13. opt.state |= QStyle::State_Enabled;
    14. opt.rect = option.rect.adjusted(1, 1, -1, -1);
    15. opt.text = trUtf8("Button text");
    16. QApplication::style()->drawControl(QStyle::CE_PushButton, &opt, painter, 0);
    17. }
    To copy to clipboard, switch view to plain text mode 

    the question is on point :
    State s = (State)(index.data(Qt::UserRole).toInt());
    and
    if (s == Hovered)
    or
    if (s == Pressed)

    i use qt 4.8 may be that some constants are changed?

  2. #2
    Join Date
    Sep 2011
    Posts
    1,245
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: qpushbutton delegate

    No. those are your constants... How does Qt know what State is?

    but it would have been considerate for you to mention change *relative to what*.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: qpushbutton delegate

    Quote Originally Posted by amleto View Post
    No. those are your constants...
    Exactly as the OP explained in the thread to which we weren't provided a link.
    (State is my own enum)

Similar Threads

  1. Need help with my delegate
    By Guilo in forum Qt Programming
    Replies: 6
    Last Post: 1st July 2010, 12:15
  2. Is delegate necessary here?
    By scythe in forum Qt Programming
    Replies: 1
    Last Post: 22nd June 2010, 19:59
  3. Replies: 0
    Last Post: 22nd February 2010, 09:30
  4. Delegate but when
    By uygar in forum Qt Programming
    Replies: 1
    Last Post: 12th October 2007, 20:28
  5. Replies: 3
    Last Post: 26th September 2006, 12:16

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.