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. Irregular progress chart
Forum Updated to NodeBB v4.3 + New Features

Irregular progress chart

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 2 Posters 424 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.
  • R Offline
    R Offline
    raziel
    wrote on last edited by
    #1

    Hello,
    Im currently trying to find best way to draw a chart, which shows progress of subpieces of an item. Im migrating from old Forms application where looked like this:
    10feec82-272e-453b-b988-d2758e64deed-image.png (grey meant not done, orange working, blue done)

    In Forms it was achieved using bar chart with zero padding between hundreds/thousands of bars (of orange/blue series which were without offset)

    It doesnt look like such styling is easily possible with QChart QBarSet, or is there some chart type ideal for this?

    Alternative could also be to draw manually vertical lines to QImage and then draw it in paintEvent to fill some QWidget. Considering such information is additive (only draw more lines on top of existing chart/image during update) could this be better option? Is it even possible to draw more to shown image or whole image needs to be repainted?

    Thank you for suggestions

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      I would simply draw the lines on a QImage when an update is coming in and then draw this image in the paintEvent() of a custom QWidget or QLabel.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      R 1 Reply Last reply
      1
      • Christian EhrlicherC Christian Ehrlicher

        I would simply draw the lines on a QImage when an update is coming in and then draw this image in the paintEvent() of a custom QWidget or QLabel.

        R Offline
        R Offline
        raziel
        wrote on last edited by
        #3

        @Christian-Ehrlicher
        If I understand right, this would mean one QPainter in update function for drawing new lines on image (QPainter ::drawLine) + call repaint() or update(), and second inside paintEvent for

        QPainter painter(this);
        painter.drawImage(rect(), dataImage);
        painter.end();
        

        It looks a bit wasteful to redraw it whole when only small parts change at a time, but is there a way to edit existing painted image? And I presume this would work for arbitrary image size (if I set image width to chart varying subparts count), and stretch accordingly?

        Christian EhrlicherC 1 Reply Last reply
        0
        • R raziel

          @Christian-Ehrlicher
          If I understand right, this would mean one QPainter in update function for drawing new lines on image (QPainter ::drawLine) + call repaint() or update(), and second inside paintEvent for

          QPainter painter(this);
          painter.drawImage(rect(), dataImage);
          painter.end();
          

          It looks a bit wasteful to redraw it whole when only small parts change at a time, but is there a way to edit existing painted image? And I presume this would work for arbitrary image size (if I set image width to chart varying subparts count), and stretch accordingly?

          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @raziel said in Irregular progress chart:

          but is there a way to edit existing painted image?

          No it isn't.

          You can call update() (repaint is a forced draw which is not really needed in 99,9% of all cases) with a dirty rect and then set the clip rect so QPainter draws only in the clip rect if you've performance problems.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          R 1 Reply Last reply
          1
          • Christian EhrlicherC Christian Ehrlicher

            @raziel said in Irregular progress chart:

            but is there a way to edit existing painted image?

            No it isn't.

            You can call update() (repaint is a forced draw which is not really needed in 99,9% of all cases) with a dirty rect and then set the clip rect so QPainter draws only in the clip rect if you've performance problems.

            R Offline
            R Offline
            raziel
            wrote on last edited by
            #5

            @Christian-Ehrlicher

            Thank you, it works fairly well
            2d7ea616-f66d-4a2a-8088-65fa8a05c1af-image.png
            although there is a bit of unwanted blurring (bilinear filtering?) despite using

            pixmap.scaled(widgetWidth, 1, Qt::IgnoreAspectRatio, Qt::FastTransformation)
            

            which does help, but not completely.

            Do you know if there is possibility to turn off filtering completely for sharp pixelated image?

            Christian EhrlicherC 1 Reply Last reply
            0
            • R raziel

              @Christian-Ehrlicher

              Thank you, it works fairly well
              2d7ea616-f66d-4a2a-8088-65fa8a05c1af-image.png
              although there is a bit of unwanted blurring (bilinear filtering?) despite using

              pixmap.scaled(widgetWidth, 1, Qt::IgnoreAspectRatio, Qt::FastTransformation)
              

              which does help, but not completely.

              Do you know if there is possibility to turn off filtering completely for sharp pixelated image?

              Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @raziel said in Irregular progress chart:

              Do you know if there is possibility to turn off filtering completely for sharp pixelated image?

              I would resize the QImage to the current width of the widget and do the painting in there, maybe with a QTransform on the painter to avoid the needed calculations by yourself.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              R 1 Reply Last reply
              0
              • Christian EhrlicherC Christian Ehrlicher

                @raziel said in Irregular progress chart:

                Do you know if there is possibility to turn off filtering completely for sharp pixelated image?

                I would resize the QImage to the current width of the widget and do the painting in there, maybe with a QTransform on the painter to avoid the needed calculations by yourself.

                R Offline
                R Offline
                raziel
                wrote on last edited by
                #7

                @Christian-Ehrlicher
                Ah I found the culprit. Target label widget reports smaller width during initialization (after setupUi), where I created QImage for testing. Later (eg. in timer) it reports correct bigger width. Which is strange, designer shows in properties proper bigger width, are these designed properties not yet fully set after setupUi?

                Christian EhrlicherC 1 Reply Last reply
                0
                • R raziel

                  @Christian-Ehrlicher
                  Ah I found the culprit. Target label widget reports smaller width during initialization (after setupUi), where I created QImage for testing. Later (eg. in timer) it reports correct bigger width. Which is strange, designer shows in properties proper bigger width, are these designed properties not yet fully set after setupUi?

                  Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @raziel said in Irregular progress chart:

                  are these designed properties not yet fully set after setupUi?

                  The layout manager adjusts the widgets during the showEvent() to make sure everything fits.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  1 Reply Last reply
                  1

                  • Login

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