Results 1 to 9 of 9

Thread: Get checkbox of QStandardItem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2012
    Posts
    9
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Android
    Thanks
    3

    Default Re: Get checkbox of QStandardItem

    So how to use these?

    I'm not sure but I suspect this will paint the default icons in their default size, so much too small in the case of Android. Or are you thinking of a way to resize them?

    Anyway I'm experimenting with the advice in your previous post now and I feel like it will do fine.

  2. #2
    Join Date
    Dec 2012
    Posts
    9
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Android
    Thanks
    3

    Default Re: Get checkbox of QStandardItem

    I managed to get by with the paint() method, but I'm kinda stuck with editorEvent(). Edit: I had a look at QItemDelegate source and found how to do it:
    Qt Code:
    1. bool CheckableItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
    2. {
    3. Q_UNUSED(option);
    4. if (event->type() == QEvent::MouseButtonRelease) {
    5. QVariant value = index.data(Qt::CheckStateRole);
    6. Qt::CheckState state = (static_cast<Qt::CheckState>(value.toInt()) == Qt::Checked
    7. ? Qt::Unchecked : Qt::Checked);
    8. return model->setData(index, state, Qt::CheckStateRole);
    9. } else
    10. return false;
    11. }
    To copy to clipboard, switch view to plain text mode 

    This will intercept all mouse clicks on the item (and I'm ok with it).
    Last edited by Neptilo; 2nd December 2014 at 16:49.

  3. #3
    Join Date
    Dec 2012
    Posts
    9
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Android
    Thanks
    3

    Red face Re: Get checkbox of QStandardItem

    Update:

    I think I nailed it, hinted by this post.

    So I subclassed QProxyStyle as AndroidStyle and reimplemented QProxyStyle::pixelMetric this way:

    Qt Code:
    1. int AndroidStyle::pixelMetric(PixelMetric which,
    2. const QStyleOption *option,
    3. const QWidget *widget) const
    4. {
    5. int metric = QProxyStyle::pixelMetric(which, option, widget);
    6. switch (which) {
    7. case PM_IndicatorWidth:
    8. case PM_IndicatorHeight:
    9. return 2*metric;
    10. default:
    11. return metric;
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 

    and I set this style in the main function like this:
    Qt Code:
    1. QApplication a(argc, argv);
    2. a.setStyle(new AndroidStyle);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Reimplemented QStandardItem
    By Miga in forum Qt Programming
    Replies: 6
    Last Post: 3rd April 2012, 14:48
  2. Replies: 4
    Last Post: 1st June 2011, 14:54
  3. setObjectName for QStandardItem
    By abk883 in forum Newbie
    Replies: 1
    Last Post: 20th May 2010, 18:20
  4. UTF8 and QStandardItem?
    By alexandernst in forum Newbie
    Replies: 17
    Last Post: 26th July 2009, 18:29
  5. QStandardItem question.
    By alexandernst in forum Qt Programming
    Replies: 6
    Last Post: 21st July 2009, 01:01

Tags for this Thread

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.