Results 1 to 3 of 3

Thread: Progress bar form QLineEdit issue

  1. #1
    Join Date
    May 2013
    Location
    Bialystok/Poland
    Posts
    13
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Lightbulb Progress bar form QLineEdit issue

    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 

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Progress bar form QLineEdit issue

    Haven't tried it but shouln't it be possible to simple set your background gradient into the palette of the line edit before calling the base class implementations QLineEdit::paint()?

  3. The following user says thank you to Lykurg for this useful post:

    RafalNiewinski (2nd June 2013)

  4. #3
    Join Date
    May 2013
    Location
    Bialystok/Poland
    Posts
    13
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Smile Re: Progress bar form QLineEdit issue

    Ok thanks

    this is solved my problem:
    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. if(hasFocus() || progress == 100) QLineEdit::paintEvent(event);
    8.  
    9. QPainter painter(this);
    10. initStyleOption(&lenap);
    11. QRect backgroundRect = style()->subElementRect(QStyle::SE_LineEditContents, &lenap, this);
    12.  
    13. if(!hasFocus() && progress < 100)
    14. {
    15. QColor loadingColor = QColor(116, 192, 250);
    16. painter.setBrush(generateGradient(loadingColor));
    17. painter.setPen(Qt::transparent);
    18. int mid = backgroundRect.width() / 100 * progress;
    19. QRect progressRect(backgroundRect.x(), backgroundRect.y(), mid, backgroundRect.height());
    20. painter.drawRect(progressRect);
    21.  
    22. painter.setPen(Qt::SolidLine);
    23. painter.drawText(backgroundRect,Qt::AlignLeft|Qt::AlignVCenter, " " + this->text());
    24. }
    25. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. issue focusing QLineEdit rendered to QGraphicsScene
    By rndbit in forum Qt Programming
    Replies: 0
    Last Post: 29th January 2011, 12:47
  2. Replies: 2
    Last Post: 12th September 2010, 19:01
  3. Form QLineEdit
    By waynew in forum Newbie
    Replies: 4
    Last Post: 5th November 2009, 21:16
  4. The issue on Form's size
    By adorp in forum Qt Programming
    Replies: 2
    Last Post: 23rd July 2007, 18:30
  5. [QT4 & XP] QTreeView issue with Designer form
    By incapacitant in forum Newbie
    Replies: 3
    Last Post: 2nd March 2006, 17:42

Tags for this Thread

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.