Results 1 to 1 of 1

Thread: [solved] QLineEdit with progress bar

  1. #1
    Join Date
    Feb 2011
    Posts
    16
    Qt products
    Qt5
    Platforms
    Windows

    Default [solved] QLineEdit with progress bar

    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

    Qt Code:
    1. void MyLineEdit::paintEvent(QPaintEvent *event)
    2. {
    3. if(hasFocus())
    4. {
    5. QLineEdit::paintEvent(event);
    6. }
    7. else
    8. {
    9. QPainter painter(this);
    10. initStyleOption(&panel);
    11. style()->drawPrimitive(QStyle::PE_PanelLineEdit, &panel, &painter, this);
    12.  
    13. initStyleOption(&tmp);
    14. QRect contentRect = style()->subElementRect(QStyle::SE_LineEditContents, &tmp, this);
    15.  
    16. QColor color = QColor(77, 146, 33);
    17. painter.setBrush(QBrush(color));
    18. painter.setPen(Qt::transparent);
    19. int end = contentRect.width() / 100 * progress;
    20. QRect progressRect(contentRect.x(), contentRect.y(), end, contentRect.height());
    21. painter.drawRect(progressRect);
    22.  
    23. painter.setPen(Qt::SolidLine);
    24. painter.drawText(contentRect, Qt::AlignLeft|Qt::AlignVCenter, " " + text());
    25. }
    26. }
    To copy to clipboard, switch view to plain text mode 

    Edit: stupid error, never mind....
    Attached Images Attached Images
    Last edited by smoon; 27th May 2014 at 15:06.

Similar Threads

  1. Progress bar form QLineEdit issue
    By RafalNiewinski in forum Qt Programming
    Replies: 2
    Last Post: 2nd June 2013, 11:19
  2. How to use progress bar
    By bijay in forum Newbie
    Replies: 1
    Last Post: 28th March 2012, 11:44
  3. Replies: 1
    Last Post: 12th October 2010, 23:20
  4. Replies: 4
    Last Post: 11th March 2008, 12:44
  5. Reg - Progress bar
    By suresh in forum Qt Programming
    Replies: 1
    Last Post: 12th December 2006, 16:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.