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. Direct drawing on UI
QtWS25 Last Chance

Direct drawing on UI

Scheduled Pinned Locked Moved Solved General and Desktop
17 Posts 3 Posters 5.2k 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.
  • MiklM Offline
    MiklM Offline
    Mikl
    wrote on last edited by Mikl
    #1

    Hello,

    I am making QT app with need to display images (from camera or HDD) in real time.
    I am looking for fastest way to do this.
    Ideal is to copy RGB data directly into video memory.

    I am new in QT.

    In .NET I can make object to draw from any Control (analog of Widget) like this:
    Graphics g = control.CreateGraphics();
    using this object draw anything on Control like this:
    g.DrawRect
    g.DrawImage
    g.DrawPixel
    ...
    and even have direct access to the memory and make memcopy(...);

    Can i do the same in QT?
    Is any other way is exist?

    Thank for the answer.

    THE SOLUTION

    I need to use paint event

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi, welcome to the Qt forum! Have a look at QOpenGLWidget Class for hardware accelerated graphics and see QPainter Class to learn about 2D drawing operations.

      1 Reply Last reply
      1
      • MiklM Offline
        MiklM Offline
        Mikl
        wrote on last edited by
        #3

        Hello.
        Thank you for welcoming. Hope i can find my way in QT with your help.

        I had a short a look on it and have some questions

        -Is QOpenGLWidget hardware/software depended?
        -Can i attach QPainter to widget outside of paint event. For example like this:
        QPainter* DrawTool = new QPainter(DrawWidgetName);

        May be you can point me to some examples?

        Thank you in advance.

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

          hi
          No, you are not allowed to paint outside paintEvent of the widget.
          You can cheat and draw on image and show image though.

          here is small sample of that
          https://www.dropbox.com/s/qwde8lb0fkjrrh3/mycheapgraph.zip?dl=0

          1 Reply Last reply
          1
          • MiklM Offline
            MiklM Offline
            Mikl
            wrote on last edited by Mikl
            #5

            Hi

            And it is fast enough?

            I mean it will not take my RGB, convert it to Image, when to Pixmap, when use slow OS methods to display,....

            The reason i asking, similar way in .NET is terribly slow.

            Update:
            Some more questions:
            -Can i pass my image (RGB data in a memory) to paintEvent(QPaintEvent *)?
            -Can it be inside of QPaintEvent?
            -How to pass it? Something like this: videoFrame->update(RGBPointer)?
            -Pass image using global variable?

            mrjjM 1 Reply Last reply
            0
            • MiklM Mikl

              Hi

              And it is fast enough?

              I mean it will not take my RGB, convert it to Image, when to Pixmap, when use slow OS methods to display,....

              The reason i asking, similar way in .NET is terribly slow.

              Update:
              Some more questions:
              -Can i pass my image (RGB data in a memory) to paintEvent(QPaintEvent *)?
              -Can it be inside of QPaintEvent?
              -How to pass it? Something like this: videoFrame->update(RGBPointer)?
              -Pass image using global variable?

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

              @Mikl
              hi
              sorry just saw the question about painting outside of event.
              You should use opengl :) The sample to draw on pixmap will have way to much overhead.

              -Can i pass my image (RGB data in a memory) to paintEvent(QPaintEvent *)?
              No, it has fixed signature so u cant change it. (adding the param)

              -Can it be inside of QPaintEvent?
              yes. should not be an issue

              -How to pass it? Something like this: videoFrame->update(RGBPointer)?
              Really depends on what format you get from camera.

              -Pass image using global variable?
              nope. never really a reason to use globals.
              since you might create your own widget , you can just add a function
              to assign/share the data from the source.

              1 Reply Last reply
              0
              • MiklM Offline
                MiklM Offline
                Mikl
                wrote on last edited by
                #7

                Hi

                -I like the way to draw on opengl. Should be 'fast'. But will i meet capability problem? it will run on Win AND Linux?
                Can you point me to the example, please?

                -Pass image using global variable?
                never was thinking about it. just looking for solution

                -Can i pass my image (RGB data in a memory) to paintEvent(QPaintEvent *)?
                -Can it be inside of QPaintEvent?
                -How to pass it? Something like this: videoFrame->update(RGBPointer)?
                From camera i have raw 24bit RGB data.
                If it is not possible to pass my data to paintEvent(QPaintEvent *) how can i get it? Even if it is inside of QPaintEvent. Not really see how to do it. I will start something. Correct/add me please.

                main()
                {
                char* RGBData = new char[frame size];//data from camera
                
                videoFrame = new VideoFrameWidget();
                videoFrame->update(RGBData);
                }
                
                class VideoFrameWidget : public QWidget
                {
                	Q_OBJECT
                public:
                	VideoFrameWidget(QWidget *parent);
                	virtual void paintEvent(QPaintEvent *);
                };
                
                void VideoFrameWidget::paintEvent(QPaintEvent *data)
                {
                //use opengl to draw image from data
                }
                
                1 Reply Last reply
                0
                • mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  hi
                  why cant RGBData just live in VideoFrameWidget ?
                  so you dont need to give it from main. ?

                  but else u just use functions to give it to the widget.

                  MiklM 1 Reply Last reply
                  0
                  • mrjjM mrjj

                    hi
                    why cant RGBData just live in VideoFrameWidget ?
                    so you dont need to give it from main. ?

                    but else u just use functions to give it to the widget.

                    MiklM Offline
                    MiklM Offline
                    Mikl
                    wrote on last edited by
                    #9

                    @mrjj

                    It can, but i found it not logic. it is coming from the camera.
                    It was simplification of main. In a reality it will be a loop.

                    If i understood you correctly, you propose to do it like this:

                    main()
                    {
                     char* RGBData;//data from camera
                     VideoFrameWidget videoFrame = new VideoFrameWidget();
                     CameraDevice videoSource = new CameraDevice ();
                    
                     for(;;)
                     {
                      RGBData = videoSource->getFrame();
                      videoFrame->setFrame(RGBData);
                      videoFrame->update();
                     }
                    }
                    
                    class VideoFrameWidget : public QWidget
                    {
                        Q_OBJECT
                    public:
                        VideoFrameWidget(QWidget *parent);
                        virtual void paintEvent(QPaintEvent *);
                        void setFrame(char* newFrameData);
                    private:
                     char* frameData;
                    };
                    
                    void VideoFrameWidget::paintEvent(QPaintEvent*)
                    {
                    //use opengl to draw image from frameData 
                    }
                    
                     void VideoFrameWidget::setFrame(char* newFrameData)
                    {
                     frameData = newFrameData;
                    }
                    
                    1 Reply Last reply
                    0
                    • mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      yes exactly and then u can use
                      char* frameData;
                      in paintEvent

                      MiklM 1 Reply Last reply
                      0
                      • mrjjM mrjj

                        yes exactly and then u can use
                        char* frameData;
                        in paintEvent

                        MiklM Offline
                        MiklM Offline
                        Mikl
                        wrote on last edited by
                        #11

                        @mrjj

                        But i still have a question of realization of paintEvent :)

                        Can you give me a hand, please

                        mrjjM 1 Reply Last reply
                        0
                        • MiklM Mikl

                          @mrjj

                          But i still have a question of realization of paintEvent :)

                          Can you give me a hand, please

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

                          @Mikl
                          hii . super :)
                          im not good with opengl so better ask @Wieland
                          or anyone using it often. :)

                          1 Reply Last reply
                          0
                          • MiklM Offline
                            MiklM Offline
                            Mikl
                            wrote on last edited by
                            #13

                            @mrjj
                            Thank you for helping

                            @Wieland
                            Can i ask for help with my problem please?
                            I need to display raw RGB on a screen in a fastest way.

                            mrjjM 1 Reply Last reply
                            0
                            • MiklM Mikl

                              @mrjj
                              Thank you for helping

                              @Wieland
                              Can i ask for help with my problem please?
                              I need to display raw RGB on a screen in a fastest way.

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

                              @Mikl
                              note, this is user run forum.
                              so he might first be on in the evening.
                              :)

                              MiklM 1 Reply Last reply
                              0
                              • mrjjM mrjj

                                @Mikl
                                note, this is user run forum.
                                so he might first be on in the evening.
                                :)

                                MiklM Offline
                                MiklM Offline
                                Mikl
                                wrote on last edited by Mikl
                                #15

                                @mrjj
                                Ok. Thanks.

                                For me it is looks strange, but reading this example
                                http://doc.qt.io/qt-5/qtopengl-2dpainting-example.html
                                i found, what the only different is using GLWidget as base class.
                                All painting is done by the same QPainter.

                                Am i right?

                                If it is so, task can be really simple.
                                Maybe you know the fastest way to paint from RGB raw data on widget: draw line by line, pixel by pixel, memcopy,....

                                mrjjM ? 2 Replies Last reply
                                0
                                • MiklM Mikl

                                  @mrjj
                                  Ok. Thanks.

                                  For me it is looks strange, but reading this example
                                  http://doc.qt.io/qt-5/qtopengl-2dpainting-example.html
                                  i found, what the only different is using GLWidget as base class.
                                  All painting is done by the same QPainter.

                                  Am i right?

                                  If it is so, task can be really simple.
                                  Maybe you know the fastest way to paint from RGB raw data on widget: draw line by line, pixel by pixel, memcopy,....

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

                                  @Mikl
                                  Yes as far as i know its VERY similar to
                                  normal widget drawing even when opengl.
                                  (when 2d)

                                  well, the sample i have seen , used something like
                                  uchar* data = getDataFromSomewhere();
                                  QImage img(data, width, height, QImage::Format_ARGB32);
                                  and then convert ot pixmap and draw.
                                  or directly into pixmap with
                                  http://doc.qt.io/qt-4.8/qpixmap.html#loadFromData

                                  1 Reply Last reply
                                  0
                                  • MiklM Mikl

                                    @mrjj
                                    Ok. Thanks.

                                    For me it is looks strange, but reading this example
                                    http://doc.qt.io/qt-5/qtopengl-2dpainting-example.html
                                    i found, what the only different is using GLWidget as base class.
                                    All painting is done by the same QPainter.

                                    Am i right?

                                    If it is so, task can be really simple.
                                    Maybe you know the fastest way to paint from RGB raw data on widget: draw line by line, pixel by pixel, memcopy,....

                                    ? Offline
                                    ? Offline
                                    A Former User
                                    wrote on last edited by
                                    #17

                                    @Mikl said:

                                    For me it is looks strange, but reading this example
                                    http://doc.qt.io/qt-5/qtopengl-2dpainting-example.html
                                    i found, what the only different is using GLWidget as base class.
                                    All painting is done by the same QPainter.

                                    Am i right?

                                    Hi! Yes, getting 2D hardware acceleration for QPainter is really easy :)

                                    1 Reply Last reply
                                    2

                                    • Login

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