{
initStyleOption(&panel);
style
()->drawPrimitive
(QStyle::PE_PanelLineEdit,
&panel,
&p,
this);
if(hasFocus
() || progress
== 100) QLineEdit::paintEvent(event
);
initStyleOption(&lenap);
QRect backgroundRect
= style
()->subElementRect
(QStyle::SE_LineEditContents,
&lenap,
this);
if(!hasFocus() && progress < 100)
{
painter.setBrush(generateGradient(loadingColor));
painter.setPen(Qt::transparent);
int mid = backgroundRect.width() / 100 * progress;
QRect progressRect
(backgroundRect.
x(), backgroundRect.
y(), mid, backgroundRect.
height());
painter.drawRect(progressRect);
painter.setPen(Qt::SolidLine);
painter.drawText(backgroundRect,Qt::AlignLeft|Qt::AlignVCenter, " " + this->text());
}
}
void MyLineEdit::paintEvent(QPaintEvent * event)
{
QPainter p(this);
QStyleOptionFrameV2 panel;
initStyleOption(&panel);
style()->drawPrimitive(QStyle::PE_PanelLineEdit, &panel, &p, this);
if(hasFocus() || progress == 100) QLineEdit::paintEvent(event);
QPainter painter(this);
QStyleOptionFrameV2 lenap;
initStyleOption(&lenap);
QRect backgroundRect = style()->subElementRect(QStyle::SE_LineEditContents, &lenap, this);
if(!hasFocus() && progress < 100)
{
QColor loadingColor = QColor(116, 192, 250);
painter.setBrush(generateGradient(loadingColor));
painter.setPen(Qt::transparent);
int mid = backgroundRect.width() / 100 * progress;
QRect progressRect(backgroundRect.x(), backgroundRect.y(), mid, backgroundRect.height());
painter.drawRect(progressRect);
painter.setPen(Qt::SolidLine);
painter.drawText(backgroundRect,Qt::AlignLeft|Qt::AlignVCenter, " " + this->text());
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks