Results 1 to 7 of 7

Thread: QPainter Event help

  1. #1
    Join Date
    Jul 2017
    Posts
    13
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QPainter Event help

    Hello Friends

    I want to Freeze paint event on my button click in my main window and release the paint event on my button release. Any Example code or snippet will be helpful.

    Thanks in Advance.


    Can I Freeze paint event in QPainter end() method?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPainter Event help

    What do you mean by "freeze paint event"? If you want to stop updates of a widget then render the widget to a pixmap (using QWidget::render()) and in the paintEvent render that pixmap instead of calling the base class implementation of paintEvent().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jul 2017
    Posts
    13
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Re: QPainter Event help

    [ATTACH=CONFIG]12572
    Hi Wysota

    Thanks For the reply. I have done graph plotting using qtpaint event. I want to Freeze Graph on my button Click. I googled this info but no luck. is there any method to achieve Grpah freeze method using Qt paintevent
    I don't have a Idea To freeze Graph like a screen shot.

    [

    Here is my code :

    This paint event triggered by timer


    void GraphArea_Single_ECG_1::paintEvent(QPaintEvent *Mypaint)
    {
    Q_UNUSED(Mypaint);
    QPainter Single_ECG_1_Painter(this);

    if(Screen_Empty_Flag == false)
    {
    QPen Pen_Single_ECG_1(Qt::green);
    Pen_Single_ECG_1.setWidth(2);
    Single_ECG_1_Painter.setPen(Pen_Single_ECG_1);
    Single_ECG_1_Painter.setRenderHint(QPainter::Antia liasing,true);

    Single_ECG_1_Painter.drawLine(X_Position, (127 - Single_ECG_1_Previous_Graph_data) +075, X_Position+1, (127 - Single_ECG_1_Current_Graph_data) +075);

    QPen gap (Qt::black);
    Single_ECG_1_Painter.setPen(gap);
    Single_ECG_1_Painter.drawRect(X_Position+ 5, 0, 1, 1000);
    Single_ECG_1_Painter.drawRect(X_Position+10, 0, 1, 1000);
    Single_ECG_1_Painter.drawRect(X_Position+15, 0, 1, 1000);

    Single_ECG_1_Previous_Graph_data = Single_ECG_1_Current_Graph_data;
    }

    else
    {
    QBrush brush(Qt::black, Qt::SolidPattern);
    Single_ECG_1_Painter.fillRect(0, 0, 2000, 1000, brush);
    X_Position = 0;
    Screen_Empty_Flag = false;
    }
    }


    /****Qt paint Event Trigger Function ******/

    void GraphArea_Single_ECG_1::Timer_Single_ECG_1_Timeout ()
    {
    if(!Array_ECG_1_Data.isEmpty())
    {
    Single_ECG_1_Current_Graph_data = Array_ECG_1_Data.takeFirst() + 100;
    }

    X_Position++;
    if(X_Position > Graph_Width)
    X_Position=0;

    this->update();
    }

    /**********Timer Inialization**********/

    void GraphArea_Single_ECG_1::Timer_Initialization_Singl e_ECG_1()
    {
    Timer_Single_ECG_1 = new QTimer(this);
    Timer_Single_ECG_1->setInterval(6);
    connect(Timer_Single_ECG_1, SIGNAL(timeout()), this, SLOT(Timer_Single_ECG_1_Timeout()));

    }]
    Attached Images Attached Images

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPainter Event help

    Could you explain what you mean by "graph freeze"?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QPainter Event help

    @wysota I think he means that when a button is clicked that graph which is otherwise moving on the time axist stops to advance hence "freeze", and I imagine, once "released" the graph should continue from its current position (as if it continued to move in the background).

    @OP
    One way might be that when you want to "freeze" you can simply set a flag, and check that flag in Timer_Single_ECG_1_Timeout ().
    Like this:
    Qt Code:
    1. void GraphArea_Single_ECG_1::Timer_Single_ECG_1_Timeout ()
    2. {
    3. if(!m_bFreeze){ //m_bFreeze is a bool which gets true when you pressed a button for freeze or some other way to trigger freeze.
    4. if( !Array_ECG_1_Data.isEmpty())
    5. {
    6. Single_ECG_1_Current_Graph_data = Array_ECG_1_Data.takeFirst() + 100;
    7. }
    8.  
    9. X_Position++;
    10. if(X_Position > Graph_Width)
    11. X_Position=0;
    12. }
    13.  
    14. this->update();
    15. }
    To copy to clipboard, switch view to plain text mode 
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  6. The following user says thank you to high_flyer for this useful post:

    vivekyuvan (29th August 2017)

  7. #6
    Join Date
    Jul 2017
    Posts
    13
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QPainter Event help

    Quote Originally Posted by high_flyer View Post
    @wysota I think he means that when a button is clicked that graph which is otherwise moving on the time axist stops to advance hence "freeze", and I imagine, once "released" the graph should continue from its current position (as if it continued to move in the background).

    @OP
    One way might be that when you want to "freeze" you can simply set a flag, and check that flag in Timer_Single_ECG_1_Timeout ().
    Like this:
    Qt Code:
    1. void GraphArea_Single_ECG_1::Timer_Single_ECG_1_Timeout ()
    2. {
    3. if(!m_bFreeze){ //m_bFreeze is a bool which gets true when you pressed a button for freeze or some other way to trigger freeze.
    4. if( !Array_ECG_1_Data.isEmpty())
    5. {
    6. Single_ECG_1_Current_Graph_data = Array_ECG_1_Data.takeFirst() + 100;
    7. }
    8.  
    9. X_Position++;
    10. if(X_Position > Graph_Width)
    11. X_Position=0;
    12. }
    13.  
    14. this->update();
    15. }
    To copy to clipboard, switch view to plain text mode 
    @high_flyer Thanks for Your Reply.You got my point Exactly, I will Try this method.

  8. #7
    Join Date
    Jul 2017
    Posts
    13
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QPainter Event help

    @high_flyer I followed your instruction now my problem is solved. thanks for the reply.

Similar Threads

  1. Replies: 2
    Last Post: 26th December 2012, 01:03
  2. QPainter immediate drawing outside paint event
    By sfcheng77 in forum Qt Programming
    Replies: 1
    Last Post: 23rd February 2011, 06:39
  3. Replies: 1
    Last Post: 5th October 2010, 17:08
  4. Replies: 5
    Last Post: 7th September 2009, 20:57
  5. Replies: 3
    Last Post: 30th April 2006, 19:22

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.