![](/img/trans.png)
[英]QLabel text not selectble even when i set Qt::TextSelectableByMouse inside QStyledItemDelegate
[英]How to set the orientation of a QStyleOptionProgressBar inside a QStyledItemDelegate
我正在使用 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;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.