PDA

View Full Version : [solved] QLineEdit with progress bar



smoon
27th May 2014, 14:16
Hi,

I want to combine a QLineEdit widget with a progress bar, but I have some problems with the drawing as you can see in the attachment (the shown values are the progress in percent). I don't know how to determine the correct width of the content rectangle. Here my code for the paint event



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());
}
}


Edit: stupid error, never mind....