RafalNiewinski
29th May 2013, 19:09
Hello, It is my first post on the QtCentre forum so please correct any mistakes.
I have a problem with create something like QProgressBar from QLineEdit (QLineEdit functionality + QProgressBar functionality in one QWidget).
I created a class derived from QLineEdit which overloads paintEvent method.
Progress functionality works fine but I am lost QLineEdit functions such as carriage drawing, visibility of text selection etc.
My paintEvent method:
void MyLineEdit::paintEvent(QPaintEvent * event)
{
QPainter p(this);
QStyleOptionFrameV2 panel;
initStyleOption(&panel);
style()->drawPrimitive(QStyle::PE_PanelLineEdit, &panel, &p, this);
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());
}
I have a problem with create something like QProgressBar from QLineEdit (QLineEdit functionality + QProgressBar functionality in one QWidget).
I created a class derived from QLineEdit which overloads paintEvent method.
Progress functionality works fine but I am lost QLineEdit functions such as carriage drawing, visibility of text selection etc.
My paintEvent method:
void MyLineEdit::paintEvent(QPaintEvent * event)
{
QPainter p(this);
QStyleOptionFrameV2 panel;
initStyleOption(&panel);
style()->drawPrimitive(QStyle::PE_PanelLineEdit, &panel, &p, this);
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());
}