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. Drawing on an Image!
Forum Updated to NodeBB v4.3 + New Features

Drawing on an Image!

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 4 Posters 2.1k Views 1 Watching
  • 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.
  • J Offline
    J Offline
    jrod2much
    wrote on last edited by jrod2much
    #1

    Hello,

    So, I am working on a project. Basically I have data from a camera about the color that the camera is viewing. The camera gives me color values that I can express in the form of an x and a y coordinate that can be plotted on a chromaticity graph.

    I was thinking that I could display an image on the Qt interface of a chromaticity graph and then, using the x and y coordinates, draw some sort of point in the specified location of the image of the graph.

    What are the Qt classes I should be looking at in order to accomplish this goal or is there a better way? Thank you in advance.

    Juan

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      is the chromaticity graph a fixed image?

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      1
      • J Offline
        J Offline
        jrod2much
        wrote on last edited by
        #3

        Yes, It would be something like this:

        0_1540305397147_c1a7e2f0-df49-4fb1-83ef-76f6da724996-image.png

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi
          If the graph is just a plain image, you can just draw on it using QPainter.
          A custom widget with its own paintEvent could easy be made or
          simply use a QLabel and its setPixmap method.
          You can connect a QPainter to an image and that way draw on the image.

          here is sample of painting on a pixmap using QLabel to display it
          https://www.dropbox.com/s/qwde8lb0fkjrrh3/mycheapgraph.zip?dl=0
          result:
          alt text

          P 1 Reply Last reply
          4
          • J Offline
            J Offline
            jrod2much
            wrote on last edited by
            #5

            Thank you so much @mrjj. I want to be able to have a real-time update of a coordinate on the graph. So if the user presses a button, a coordinate point, maybe the shape of a plus or X with show up at a specific place on the graph image, but if the user presses the button again and the coordinate is different, it removes the first point and places a new coordinate symbol in the new place. Which of the two methods you presented would be more geared towards this.

            mrjjM 1 Reply Last reply
            0
            • J jrod2much

              Thank you so much @mrjj. I want to be able to have a real-time update of a coordinate on the graph. So if the user presses a button, a coordinate point, maybe the shape of a plus or X with show up at a specific place on the graph image, but if the user presses the button again and the coordinate is different, it removes the first point and places a new coordinate symbol in the new place. Which of the two methods you presented would be more geared towards this.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @jrod2much
              Hi
              The custom widget with paintEvent should be slightly faster than QLabel+pixmap.
              Also, it's easier to keep a copy of graph image around so you can erase a point by
              copying it over with a rect from the original image. ( so its partial update / erase for fast(er) performance )

              However, its not surely the QLabel way would be too slow (at all), but overall a custom widget
              is preferred as its also a more self-contained solution and could handle all
              erase/redraw of points transparent to the class using the widget.

              1 Reply Last reply
              3
              • J Offline
                J Offline
                jrod2much
                wrote on last edited by
                #7

                @mrjj Thank you so much, worked like a charm!

                mrjjM 1 Reply Last reply
                1
                • J jrod2much

                  @mrjj Thank you so much, worked like a charm!

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @jrod2much
                  Super. Good work. :)

                  1 Reply Last reply
                  1
                  • mrjjM mrjj

                    Hi
                    If the graph is just a plain image, you can just draw on it using QPainter.
                    A custom widget with its own paintEvent could easy be made or
                    simply use a QLabel and its setPixmap method.
                    You can connect a QPainter to an image and that way draw on the image.

                    here is sample of painting on a pixmap using QLabel to display it
                    https://www.dropbox.com/s/qwde8lb0fkjrrh3/mycheapgraph.zip?dl=0
                    result:
                    alt text

                    P Offline
                    P Offline
                    Pedro Jaime
                    wrote on last edited by
                    #9

                    @mrjj Hi, I'm Brazilian and I'm answering you through google translator. I'm sorry if anything is wrong with writing.
                    I would like to thank you for your code example that you provided here. I did not think in any corner how to draw on a label and you saved me. I only needed this to continue my college project.

                    mrjjM 1 Reply Last reply
                    1
                    • P Pedro Jaime

                      @mrjj Hi, I'm Brazilian and I'm answering you through google translator. I'm sorry if anything is wrong with writing.
                      I would like to thank you for your code example that you provided here. I did not think in any corner how to draw on a label and you saved me. I only needed this to continue my college project.

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @Pedro-Jaime
                      Welcome to the forums.
                      Actually google translate worked good.
                      Im glad it was helpful to your project.

                      1 Reply Last reply
                      0

                      • Login

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