qBittorrent
ProgressBarPainter Class Reference

#include <progressbarpainter.h>

Public Member Functions

 ProgressBarPainter ()
 
void paint (QPainter *painter, const QStyleOptionViewItem &option, const QString &text, int progress) const
 

Private Attributes

QProgressBar m_dummyProgressBar
 

Detailed Description

Definition at line 35 of file progressbarpainter.h.

Constructor & Destructor Documentation

◆ ProgressBarPainter()

ProgressBarPainter::ProgressBarPainter ( )

Definition at line 40 of file progressbarpainter.cpp.

41 {
42 #if (defined(Q_OS_WIN) || defined(Q_OS_MACOS))
43  auto *fusionStyle = new QProxyStyle {"fusion"};
44  fusionStyle->setParent(&m_dummyProgressBar);
45  m_dummyProgressBar.setStyle(fusionStyle);
46 #endif
47 }
QProgressBar m_dummyProgressBar

References m_dummyProgressBar.

Member Function Documentation

◆ paint()

void ProgressBarPainter::paint ( QPainter *  painter,
const QStyleOptionViewItem &  option,
const QString &  text,
int  progress 
) const

Definition at line 49 of file progressbarpainter.cpp.

50 {
51  QStyleOptionProgressBar styleOption;
52  styleOption.initFrom(&m_dummyProgressBar);
53  // QStyleOptionProgressBar fields
54  styleOption.maximum = 100;
55  styleOption.minimum = 0;
56  styleOption.progress = progress;
57  styleOption.text = text;
58  styleOption.textVisible = true;
59  // QStyleOption fields
60  styleOption.rect = option.rect;
61  // Qt 6 requires QStyle::State_Horizontal to be set for correctly drawing horizontal progress bar
62  styleOption.state = option.state | QStyle::State_Horizontal;
63 
64  const bool isEnabled = option.state.testFlag(QStyle::State_Enabled);
65  styleOption.palette.setCurrentColorGroup(isEnabled ? QPalette::Active : QPalette::Disabled);
66 
67  painter->save();
68  const QStyle *style = m_dummyProgressBar.style();
69  style->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter, option.widget);
70  style->drawControl(QStyle::CE_ProgressBar, &styleOption, painter, &m_dummyProgressBar);
71  painter->restore();
72 }

References m_dummyProgressBar.

Referenced by PreviewListDelegate::paint(), PropListDelegate::paint(), and TransferListDelegate::paint().

Here is the caller graph for this function:

Member Data Documentation

◆ m_dummyProgressBar

QProgressBar ProgressBarPainter::m_dummyProgressBar
private

Definition at line 44 of file progressbarpainter.h.

Referenced by paint(), and ProgressBarPainter().


The documentation for this class was generated from the following files: