Results 1 to 5 of 5

Thread: Height by value on a Custom Progress Bar ?

  1. #1
    Join Date
    Sep 2017
    Posts
    18
    Qt products
    Qt5
    Platforms
    Windows

    Question Height by value on a Custom Progress Bar ?

    Hi,

    I want to create a flat progress bar with QPainter, I paint graphics with the fallowing code:

    Qt Code:
    1. QPainter painter(this);
    2.  
    3. // Bar Background
    4. painter.setBrush(QBrush(Qt::white));
    5. painter.setPen(Qt::NoPen);
    6. painter.drawRect(0, 0, m_width, this->height());
    7.  
    8. // Bar Value
    9. painter.setBrush(QBrush(m_fillColor));
    10.  
    11. if (m_value == 0)
    12. {
    13. return;
    14. }
    15.  
    16. qDebug() << "Value: " << m_value;
    17. qDebug() << "Height: " << this->height();
    18.  
    19. int heightValue = (this->height() / m_value);
    20.  
    21. qDebug() << "HValue: " << heightValue;
    22.  
    23. painter.drawRect(0, 0, m_width, heightValue);
    To copy to clipboard, switch view to plain text mode 

    But I tried some calculation for set the height of the progress bar with the progress bar value but nothing works...

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,462
    Thanked 271 Times in 266 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Height by value on a Custom Progress Bar ?

    What it is "nothing works" ?

  3. #3
    Join Date
    Sep 2017
    Posts
    18
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Height by value on a Custom Progress Bar ?

    Sorry, I found how to do what I want, thank anyway for reply.

  4. #4
    Join Date
    Jul 2008
    Posts
    412
    Thanks
    9
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Height by value on a Custom Progress Bar ?

    ... and if you would post your solution others would probably be happy as well.

    Ginsengelf

  5. #5
    Join Date
    Sep 2017
    Posts
    18
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Height by value on a Custom Progress Bar ?

    Qt Code:
    1. int heightValue = (int)qRound(((float)currentValue / maxProgressBarValue) * heightOfTheProgressBar);
    To copy to clipboard, switch view to plain text mode 

    And I draw with QPainter a rectangle like that:
    Qt Code:
    1. painter.drawRect(0, 0, 100, heightValue);
    To copy to clipboard, switch view to plain text mode 
    Last edited by MathFurious; 8th February 2018 at 15:35. Reason: updated contents

Similar Threads

  1. Custom Progress Dialog while loading QTreeWidget
    By m3rlin in forum Qt Programming
    Replies: 5
    Last Post: 4th March 2013, 06:13
  2. Custom progress bar background for list items
    By themagician in forum Qt Programming
    Replies: 1
    Last Post: 26th February 2012, 23:07
  3. How to set custom height for ListView & ComboBox items
    By rawfool in forum Qt Programming
    Replies: 1
    Last Post: 30th September 2011, 11:39
  4. ListWidget -> custom Item -> height
    By Archa4 in forum Newbie
    Replies: 5
    Last Post: 4th February 2011, 12:36
  5. Replies: 4
    Last Post: 11th March 2008, 12:44

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.