c++ - 如何在 QStyledItemDelegate 中设置 QStyleOptionProgressBar 的方向
问题描述
我正在使用 Qt 5.15.2。我有一个QTableView
从派生的类加载数据QAbstractTableModel
。这很好用。现在我想在一列的每一行中添加一个进度条。为此,我从以下位置派生了一个类QStyledItemDelegate
:
class ProgressBarDelegate : public QStyledItemDelegate {
Q_OBJECT
public:
ProgressBarDelegate(QObject *parent = 0) : QStyledItemDelegate(parent) {}
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override {
if (index.data().canConvert<int>()) {
int progress = qvariant_cast<int>(index.data());
QStyleOptionProgressBar progressBarOption;
progressBarOption.rect = option.rect;
progressBarOption.minimum = 0;
progressBarOption.maximum = 100;
progressBarOption.progress = progress;
QStyle *style = QApplication::style();
style->drawControl(QStyle::CE_ProgressBar, &progressBarOption, painter);
} else {
QStyledItemDelegate::paint(painter, option, index);
}
}
};
它几乎可以工作,问题是进度条从下到上,如下所示:
如何从左到右更改方向?
顺便说一句,这是将进度条填充到 中的最佳方法QTableView
吗?
解决方案
缺少的行是:
progressBarOption.state = QStyle::StateFlag::State_Horizontal;
推荐阅读
- sql-server - 如何使用自定义分隔符货币值?
- lisp - 使用 read-line 从 .txt 中读取,正在读取其他符号。记事本神器?
- c# - 如何解决聚合异常?
- reactjs - 无法在组合减速器中减速器
- python - 如何找到原地操作:梯度计算所需的变量之一已被原地操作修改
- javascript - 如何将 javascript 字符串传递给控制器?
- python - 如何在 Qwizard 完成按钮插槽上进行一些验证并在 Qwizard 完成之前获得确认?
- reactjs - 未捕获(承诺中)错误:GraphQL 错误:未授权
- python-3.x - 在 localstack 上运行时与在 AWS Lambda 上运行时相比,boto3 资源需要更多参数
- google-maps - 单击多边形时显示信息窗口