Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
widgetdelegate.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4#include <QtGui>
5#include <QStyledItemDelegate>
6#include <QApplication>
7
9{
11public:
13 const QModelIndex &index) const override;
14};
15
16//![0]
17void WidgetDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
18 const QModelIndex &index) const
19{
20 if (index.column() == 1) {
21 int progress = index.data().toInt();
22
23 QStyleOptionProgressBar progressBarOption;
24 progressBarOption.rect = option.rect;
25 progressBarOption.minimum = 0;
26 progressBarOption.maximum = 100;
27 progressBarOption.progress = progress;
28 progressBarOption.text = QString::number(progress) + "%";
29 progressBarOption.textVisible = true;
30
31 QApplication::style()->drawControl(QStyle::CE_ProgressBar,
32 &progressBarOption, painter);
33 } else
34 QStyledItemDelegate::paint(painter, option, index);
35
36//![0]
37}