Results 1 to 6 of 6

Thread: Emphasizing "current item" in subclass of QAbstractItemView

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2009
    Posts
    24
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    3

    Default Re: Emphasizing "current item" in subclass of QAbstractItemView

    Thanks Lykurg.

    I'll try your suggestion next week. I also couldn't find any relevant post about the "current" item. I did find posts about “selected” item(s), but that's not the issue here.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: Emphasizing "current item" in subclass of QAbstractItemView

    Damn, everytime I came into that trouble with QStyle::State_HasFocus and QStyle::State_Selected....

    The dotted line is the result of one or these two states. So in the "selected items threads" you will find how to remove these flag inside the paint event. And there is the connection to your "current item" problem

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: Emphasizing "current item" in subclass of QAbstractItemView

    I hope I remember next time
    Qt Code:
    1. #include <QtGui>
    2.  
    3. class MyDelegate : public QItemDelegate
    4. {
    5. public:
    6. MyDelegate(QObject* parent): QItemDelegate(parent)
    7. {}
    8.  
    9. virtual void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
    10. {
    11. opt = const_cast<QStyleOptionViewItem&>(option);
    12. opt.state &= ~QStyle::State_HasFocus;
    13. QItemDelegate::paint(painter, opt, index);
    14. }
    15. };
    16.  
    17. int main(int argc, char** argv)
    18. {
    19. QApplication app(argc, argv);
    20.  
    21. QTableView view;
    22. MyDelegate delegate(&view);
    23. view.setItemDelegate(&delegate);
    24.  
    25. model.setRowCount(10);
    26. model.setColumnCount(10);
    27. for (int row = 0; row < model.rowCount(); ++row)
    28. {
    29. for (int column = 0; column < model.columnCount(); ++column)
    30. {
    31. QStandardItem* item = new QStandardItem(QString("row %0, column %1").arg(row).arg(column));
    32. model.setItem(row, column, item);
    33. }
    34. }
    35. view.setModel(&model);
    36.  
    37. view.show();
    38. return app.exec();
    39. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: Emphasizing "current item" in subclass of QAbstractItemView

    Ehm.. and change is not remove! But once you have removed it, you can paint your own emphasized border. If you want to change it directly, you have to subclass QStyle and write your own routine there. But that is more complex (QProxyStyle).

Similar Threads

  1. Replies: 1
    Last Post: 7th April 2010, 21:46
  2. Replies: 3
    Last Post: 15th February 2010, 17:27
  3. QTabWidget: how to force "no current widget"?
    By mattc in forum Qt Programming
    Replies: 4
    Last Post: 13th May 2009, 12:18
  4. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05
  5. QFile Problem~ "Unknow error" in "open(QIODevice::ReadWrite)"
    By fengtian.we in forum Qt Programming
    Replies: 3
    Last Post: 23rd May 2007, 15:58

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.