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:
Qt Code:
  1. void MyLineEdit::paintEvent(QPaintEvent * event)
  2. {
  3. QPainter p(this);
  4. initStyleOption(&panel);
  5. style()->drawPrimitive(QStyle::PE_PanelLineEdit, &panel, &p, this);
  6.  
  7. QPainter painter(this);
  8. initStyleOption(&lenap);
  9. QRect backgroundRect = style()->subElementRect(QStyle::SE_LineEditContents, &lenap, this);
  10.  
  11. if(!hasFocus() && progress < 100)
  12. {
  13. QColor loadingColor = QColor(116, 192, 250);
  14. painter.setBrush(generateGradient(loadingColor));
  15. painter.setPen(Qt::transparent);
  16. int mid = backgroundRect.width() / 100 * progress;
  17. QRect progressRect(backgroundRect.x(), backgroundRect.y(), mid, backgroundRect.height());
  18. painter.drawRect(progressRect);
  19. }
  20.  
  21. painter.setPen(Qt::SolidLine);
  22. painter.drawText(backgroundRect,Qt::AlignLeft|Qt::AlignVCenter, this->text());
  23. }
To copy to clipboard, switch view to plain text mode