{
if(hasFocus())
{
}
else
{
initStyleOption(&panel);
style
()->drawPrimitive
(QStyle::PE_PanelLineEdit,
&panel,
&painter,
this);
initStyleOption(&tmp);
QRect contentRect
= style
()->subElementRect
(QStyle::SE_LineEditContents,
&tmp,
this);
painter.
setBrush(QBrush(color
));
painter.setPen(Qt::transparent);
int end = contentRect.width() / 100 * progress;
QRect progressRect
(contentRect.
x(), contentRect.
y(), end, contentRect.
height());
painter.drawRect(progressRect);
painter.setPen(Qt::SolidLine);
painter.drawText(contentRect, Qt::AlignLeft|Qt::AlignVCenter, " " + text());
}
}
void MyLineEdit::paintEvent(QPaintEvent *event)
{
if(hasFocus())
{
QLineEdit::paintEvent(event);
}
else
{
QPainter painter(this);
QStyleOptionFrame panel;
initStyleOption(&panel);
style()->drawPrimitive(QStyle::PE_PanelLineEdit, &panel, &painter, this);
QStyleOptionFrame tmp;
initStyleOption(&tmp);
QRect contentRect = style()->subElementRect(QStyle::SE_LineEditContents, &tmp, this);
QColor color = QColor(77, 146, 33);
painter.setBrush(QBrush(color));
painter.setPen(Qt::transparent);
int end = contentRect.width() / 100 * progress;
QRect progressRect(contentRect.x(), contentRect.y(), end, contentRect.height());
painter.drawRect(progressRect);
painter.setPen(Qt::SolidLine);
painter.drawText(contentRect, Qt::AlignLeft|Qt::AlignVCenter, " " + text());
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks