Wireshark 4.7.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
percent_bar_delegate.h
Go to the documentation of this file.
1
10#ifndef PERCENTBARDELEGATE_H
11#define PERCENTBARDELEGATE_H
12
13/*
14 * @file Percent bar delegate.
15 *
16 * QStyledItemDelegate subclass that will draw a percentage value and a
17 * single-item bar chart for the specified value.
18 *
19 * This is intended to be used in QTreeWidgets to show percentage values.
20 * To use it, first call setItemDelegate:
21 *
22 * myTreeWidget()->setItemDelegateForColumn(col_pct_, new PercentBarDelegate());
23 *
24 * Then, for each QTreeWidgetItem, set a double value using setData:
25 *
26 * setData(col_pct_, Qt::UserRole, QVariant::fromValue<double>(packets_ * 100.0 / num_packets));
27 *
28 * If the item data cannot be converted to a valid double value or if its
29 * text string is non-empty then it will be rendered normally (i.e. the
30 * percent text and bar will not be drawn). This lets you mix normal and
31 * percent bar rendering between rows.
32 */
33
34#include <QStyledItemDelegate>
35
39class PercentBarDelegate : public QStyledItemDelegate
40{
41public:
46 PercentBarDelegate(QWidget *parent = 0) : QStyledItemDelegate(parent) { }
47
52 virtual QString displayText(const QVariant &, const QLocale &) const { return QString(); }
53
54protected:
61 void paint(QPainter *painter, const QStyleOptionViewItem &option,
62 const QModelIndex &index) const;
63
70 QSize sizeHint(const QStyleOptionViewItem &option,
71 const QModelIndex &index) const;
72
73};
74
75#endif // PERCENTBARDELEGATE_H
Delegate for drawing a percentage bar in an item view.
Definition percent_bar_delegate.h:40
PercentBarDelegate(QWidget *parent=0)
Constructs a PercentBarDelegate.
Definition percent_bar_delegate.h:46
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
Renders the percentage bar using the given painter and style option.
Definition percent_bar_delegate.cpp:20
virtual QString displayText(const QVariant &, const QLocale &) const
Return empty string to ensure QStyledItemDelegate::paint doesn't draw any text.
Definition percent_bar_delegate.h:52
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
Returns the size hint for the percentage bar item.
Definition percent_bar_delegate.cpp:88