Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. add qpainterpath into a QProgressBar
QtWS25 Last Chance

add qpainterpath into a QProgressBar

Scheduled Pinned Locked Moved Unsolved General and Desktop
qprogressbarqpainterqpainterpath
3 Posts 2 Posters 578 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    swankster
    wrote on 8 Aug 2022, 18:25 last edited by
    #1

    I have a CustomWidget plugin. This widget is a QFrame with the below implementation hierarchy. My Widget is working well, but I am struggling with adding a qpainter diamond shape into the qProgressBar widget. If I change my parent to spValDiamond ( new QPainter( this ) ) my diamond appears fine in my outer frame. But when set it parent to the pvValBar spValDiamond ( new QPainter( pvValBar ) ) i seem to completely loose my diamond. I have attempted making the progressbar transparent with no success.
    I am creating my image with QpainterPath and then attempting to insert that image into my QProgressBar. Once their, it will move with the spValLine.

    Controller::Controller( QWidget *parent ) :
        QFrame( parent )
      , ctrlIdLabel( new QLabel )
      , ctrlOnButton( new QPushButton )
      , idOnOffHLayout( new QHBoxLayout )
      , pvFillFrame( new QFrame )
      , pvValBar( new QProgressBar )
      , spValLine ( new QLineEdit( pvValBar ) )
      , spValDiamond ( new QPainter( pvValBar ) )
      , pvValEdit ( new QLineEdit( pvValBar ) )
      , spValEdit ( new QLineEdit )
      , pvSpVLayout( new QVBoxLayout )
      , ssrValBar( new QProgressBar )
      , pvSpSsrHLayout( new QHBoxLayout )
      , ctrlVLayout( new QVBoxLayout )
    {
    
        path = new QPainterPath();
        QRectF rect(5, 10, 6, 8 );
        path->moveTo(rect.center().x(), rect.top());
        path->lineTo(rect.right(), rect.center().y());
        path->lineTo(rect.center().x(), rect.bottom());
        path->lineTo(rect.left(), rect.center().y());
        path->lineTo(rect.center().x(), rect.top());
    }
    
    void Controller::paintEvent( QPaintEvent* )
    {
        ctrlOnOffButton();
        pvProgressBarStyleSheet();
        drawSpLine();
        pvLineEditStyleSheet();
        spLineEditStyleSheet();
        ssrProgressBarStyleSheet();
    }
    
    void Controller::drawSpLine()
    {
        int heightValue = (int)qRound( (float)m_spVal / m_spValMax * pvValBar->height() );
        spValLine->move( 0, pvValBar->height() - heightValue );
    
        spValDiamond->setBrush(QBrush(Qt::red));
        spValDiamond->fillPath(*path, QBrush(Qt::red));
    }
    
    

    I assume I am just missing something simple. but any direction would be very helpful. Thank you.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 8 Aug 2022, 19:03 last edited by
      #2

      Hi,

      You can't paint on a different widget.

      If you want to customize the QProgressBar, then you have to subclass it and do the painting in its own paintEvent.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • S Offline
        S Offline
        swankster
        wrote on 8 Aug 2022, 19:05 last edited by
        #3

        thank you for the direction.

        1 Reply Last reply
        0

        1/3

        8 Aug 2022, 18:25

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved