mytimedelegate.cpp 682 B

12345678910111213141516171819202122232425
  1. #include "mytimedelegate.h"
  2. #include <QPainter>
  3. #include <QMouseEvent>
  4. MyTimeDelegate::MyTimeDelegate(QObject* parent) :
  5. QStyledItemDelegate(parent)
  6. {
  7. }
  8. void MyTimeDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
  9. {
  10. if (nullptr == painter || !index.isValid()) {
  11. return;
  12. }
  13. QString data = index.data().toString();
  14. if (data.isEmpty()) {
  15. if ((option.state & QStyle::State_MouseOver) ||
  16. (option.state & QStyle::State_Selected)) {
  17. painter->fillRect(option.rect, c_bkColor);
  18. return;
  19. }
  20. }
  21. QStyledItemDelegate::paint(painter, option, index);
  22. }