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?
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?
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().
[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()));
}]
@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:
void GraphArea_Single_ECG_1::Timer_Single_ECG_1_Timeout () { 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. 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(); }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.
vivekyuvan (29th August 2017)
@high_flyer I followed your instruction now my problem is solved. thanks for the reply.
Bookmarks