comparison ui/separatoritemdelegate.cpp @ 273:b6c2fa8457b6

Added new list item delegate for drawing a separator.
author Raimund Renkert <rrenkert@intevation.de>
date Wed, 02 Apr 2014 13:38:10 +0200
parents
children 17e1c8f37d72
comparison
equal deleted inserted replaced
272:abac76b855b2 273:b6c2fa8457b6
1 #include <QtWidgets>
2
3 #include "separatoritemdelegate.h"
4
5 void SeparatorItemDelegate::paint(QPainter *painter,
6 const QStyleOptionViewItem &option, const QModelIndex &index) const
7 {
8 // Save the current painter.
9 painter->save();
10
11 // Get the position for separator line.
12 int topLeftY = option.rect.topLeft().y();
13 int height = option.rect.height();
14 int middle = topLeftY + (height / 2);
15
16 // Draw the first part.
17 QPen linePen(Qt::black, 2, Qt::SolidLine);
18 painter->setPen(linePen);
19 painter->drawLine(10, middle, 80, middle);
20
21 // Draw the text.
22 QString text = index.data().toString();
23 QRect rect = option.rect.adjusted(85, -2, 0, -2);
24 painter->drawText(rect.left(), rect.top(), rect.width(), rect.height(),
25 Qt::AlignVCenter|Qt::AlignLeft, text, &rect);
26
27 // Draw the second part.
28 painter->drawLine(rect.topRight().x() + 5, middle, rect.topRight().x() + 75, middle);
29
30 // Restore the painter to have an unmodified painter for the next draw
31 // action.
32 painter->restore();
33 return;
34 }

http://wald.intevation.org/projects/trustbridge/