Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 5

Qt-interest Archive, April 2007
about QPainter and paintEvent(QPaintEvent *event)


Message 1 in thread

hi, guys
i am making a gui for a cnc system by qt. now i want to draw the motion path
of the machine tools.
i want to ask , is it possible to draw sth ( a line, for example) in one of
my function not in the paintEvent(QPaintEvent *event) vitual function?
regards
fengli

Message 2 in thread

Hi,

Not do it like that. Just because of the double-buffering.

http://doc.trolltech.com/4.2/qwidget.html#paintEvent
From Qt 4.0, QWidget automatically double-buffers its painting, so
there's no need to write double-buffering code in paintEvent() to
avoid flicker.

Regards,
Liang

On 18/04/07, 张凤丽 <zhangfenglisdu@xxxxxxxxx> wrote:
> hi, guys
> i am making a gui for a cnc system by qt. now i want to draw the motion path
> of the machine tools.
> i want to ask , is it possible to draw sth ( a line, for example) in one of
> my function not in the paintEvent(QPaintEvent *event) vitual function?
> regards
> fengli
>


-- 
 [ signature omitted ] 

Message 3 in thread

Hi, friends
i do it like this, check for me.
maybe it looks stupid. if remeber well, i think it should be implement in
the paintEvent(QPaintEvent *event) vitual function.

void MainWindow::myfun()
{
      ...
      QFrame *threeDPlotFrame;
      QPainter p(threeDPlotFrame);
      p.begin();
      drawLine(int, int , int, int);
       ...
      p.end();
}

regards
fengli

2007/4/18, 张凤丽 <zhangfenglisdu@xxxxxxxxx>:
>
> hi, guys
> i am making a gui for a cnc system by qt. now i want to draw the motion
> path of the machine tools.
> i want to ask , is it possible to draw sth ( a line, for example) in one
> of my function not in the paintEvent(QPaintEvent *event) vitual function?
> regards
> fengli
>

Message 4 in thread

Hi,

> i do it like this, check for me.
> maybe it looks stupid. if remeber well, i think it should be implement 
> in the paintEvent(QPaintEvent *event) vitual function.

Exactly, this should be implemented in the paintEvent(), not in this myfun() 
function. Unless myfun() is called by paintEvent()?

--
 [ signature omitted ] 

Message 5 in thread

hi,
i did  it that just because  i wanted myfun could be call when click a
pushbutton. if i implement it in the paintEvent(), how to connect it with
the pushbutton? or the paintEvent() will be called automaticlly?
regards
fengli

2007/4/18, 张凤丽 <zhangfenglisdu@xxxxxxxxx>:
>
> Hi, friends
> i do it like this, check for me.
> maybe it looks stupid. if remeber well, i think it should be implement in
> the paintEvent(QPaintEvent *event) vitual function.
>
> void MainWindow::myfun()
> {
>       ...
>       QFrame *threeDPlotFrame;
>       QPainter p(threeDPlotFrame);
>       p.begin();
>       drawLine(int, int , int, int);
>        ...
>       p.end();
> }
>
> regards
> fengli
>
> 2007/4/18, 张凤丽 <zhangfenglisdu@xxxxxxxxx>:
> >
> > hi, guys
> > i am making a gui for a cnc system by qt. now i want to draw the motion
> > path of the machine tools.
> > i want to ask , is it possible to draw sth ( a line, for example) in one
> > of my function not in the paintEvent(QPaintEvent *event) vitual function?
> > regards
> > fengli
> >
>
>

Message 6 in thread

hi,
then i want to use a small taper as a pen when do drawings. how to  do that?
regards
fengli

2007/4/19, 张凤丽 <zhangfenglisdu@xxxxxxxxx>:
>
> hi,
> i did  it that just because  i wanted myfun could be call when click a
> pushbutton. if i implement it in the paintEvent(), how to connect it with
> the pushbutton? or the paintEvent() will be called automaticlly?
> regards
> fengli
>
> 2007/4/18, 张凤丽 <zhangfenglisdu@xxxxxxxxx>:
> >
> > Hi, friends
> > i do it like this, check for me.
> > maybe it looks stupid. if remeber well, i think it should be implement
> > in the paintEvent(QPaintEvent *event) vitual function.
> >
> > void MainWindow::myfun()
> > {
> >       ...
> >       QFrame *threeDPlotFrame;
> >       QPainter p(threeDPlotFrame);
> >       p.begin();
> >       drawLine(int, int , int, int);
> >        ...
> >       p.end();
> > }
> >
> > regards
> > fengli
> >
> > 2007/4/18, 张凤丽 <zhangfenglisdu@xxxxxxxxx>:
> > >
> > > hi, guys
> > > i am making a gui for a cnc system by qt. now i want to draw the
> > > motion path of the machine tools.
> > > i want to ask , is it possible to draw sth ( a line, for example) in
> > > one of my function not in the paintEvent(QPaintEvent *event) vitual
> > > function?
> > > regards
> > > fengli
> > >
> >
> >
>

Message 7 in thread

hi, once again
following all your advice, i change my program like this:(still check for
me.)

connect(refreshPushButton, SIGNAL(clicked()),
threeDPlotFrame, SLOT(update()));
    connect(rotXHorizontalSlide, SIGNAL(sliderPressed()),
                threeDViewFrame, SLOT(update()));
    connect(rotYHorizontalSlide, SIGNAL(sliderPressed()),
                threeDViewFrame, SLOT(update()));
    connect(rotZHorizontalSlide, SIGNAL(sliderPressed()),
                threeDViewFrame, SLOT(update()));
...
void MainWindow::paintEvent(QPaintEvent *event)
{
    QPainter p();
    p.setPen(Qt::red);
    p.setBrush(Qt::yellow, Qt::SolidPattern);
    p.setViewport(threeDPlotFrame->rect());
    p.setMatrixEnabled(true);
    p.begin(threeDViewFrame);
    myfun1();
    p.end();

    p.begin(threeDPlotFrame);
    myfun2();
    myfun3();
    p.end();
}

2007/4/19, 张凤丽 <zhangfenglisdu@xxxxxxxxx>:
>
> hi,
> then i want to use a small taper as a pen when do drawings. how to  do
> that?
> regards
> fengli
>
> 2007/4/19, 张凤丽 <zhangfenglisdu@xxxxxxxxx >:
> >
> > hi,
> > i did  it that just because  i wanted myfun could be call when click a
> > pushbutton. if i implement it in the paintEvent(), how to connect it with
> > the pushbutton? or the paintEvent() will be called automaticlly?
> > regards
> > fengli
> >
> > 2007/4/18, 张凤丽 <zhangfenglisdu@xxxxxxxxx>:
> > >
> > > Hi, friends
> > > i do it like this, check for me.
> > > maybe it looks stupid. if remeber well, i think it should be implement
> > > in the paintEvent(QPaintEvent *event) vitual function.
> > >
> > > void MainWindow::myfun()
> > > {
> > >       ...
> > >       QFrame *threeDPlotFrame;
> > >       QPainter p(threeDPlotFrame);
> > >       p.begin();
> > >       drawLine(int, int , int, int);
> > >        ...
> > >       p.end();
> > > }
> > >
> > > regards
> > > fengli
> > >
> > > 2007/4/18, 张凤丽 <zhangfenglisdu@xxxxxxxxx>:
> > > >
> > > > hi, guys
> > > > i am making a gui for a cnc system by qt. now i want to draw the
> > > > motion path of the machine tools.
> > > > i want to ask , is it possible to draw sth ( a line, for example) in
> > > > one of my function not in the paintEvent(QPaintEvent *event) vitual
> > > > function?
> > > > regards
> > > > fengli
> > > >
> > >
> > >
> >
>

Message 8 in thread

I don't know what myFunc1 and myFunc2 do, but if you want to draw things in myFunc1 and myFunc2, I think it is better to pass the QPainter obj as argument and use it to draw things Reimand.  
在2007-04-19,"张凤丽" <zhangfenglisdu@xxxxxxxxx> 写道:
hi, once again
following all your advice, i change my program like this:(still check for me.)
connect(refreshPushButton, SIGNAL(clicked()),
threeDPlotFrame, SLOT(update()));
    connect(rotXHorizontalSlide, SIGNAL(sliderPressed()),
                threeDViewFrame, SLOT(update()));
    connect(rotYHorizontalSlide, SIGNAL(sliderPressed()),
                threeDViewFrame, SLOT(update()));
    connect(rotZHorizontalSlide, SIGNAL(sliderPressed()),
                threeDViewFrame, SLOT(update()));
...
void MainWindow::paintEvent(QPaintEvent *event)
{
    QPainter p();
    p.setPen(Qt::red);
    p.setBrush(Qt::yellow, Qt::SolidPattern);
    p.setViewport(threeDPlotFrame->rect());
    p.setMatrixEnabled(true);
    p.begin(threeDViewFrame);
    myfun1();
    p.end();
   
    p.begin(threeDPlotFrame);
    myfun2();
    myfun3();
    p.end();
}
2007/4/19, 张凤丽 <zhangfenglisdu@xxxxxxxxx >:hi,
then i want to use a small taper as a pen when do drawings. how to  do that?
regards
fengli
2007/4/19, 张凤丽 <zhangfenglisdu@xxxxxxxxx>:hi,
i did  it that just because  i wanted myfun could be call when click a pushbutton. if i implement it in the paintEvent(), how to connect it with
the pushbutton? or the paintEvent() will be called automaticlly?
regards
fengli
2007/4/18, 张凤丽 <zhangfenglisdu@xxxxxxxxx>:Hi, friends
i do it like this, check for me.
maybe it looks stupid. if remeber well, i think it should be implement in the paintEvent(QPaintEvent *event) vitual function.
void MainWindow::myfun()
{
      ...
      QFrame *threeDPlotFrame;
      QPainter p(threeDPlotFrame);
      p.begin();
      drawLine(int, int , int, int);
       ...
      p.end();    
}
regards
fengli
2007/4/18, 张凤丽 <zhangfenglisdu@xxxxxxxxx>:hi, guys
i am making a gui for a cnc system by qt. now i want to draw the motion path of the machine tools.
i want to ask , is it possible to draw sth ( a line, for example) in one of my function not in the paintEvent(QPaintEvent *event) vitual function?
regards
fengli

Message 9 in thread

You can invoke update() or repaint() to let paintEvent() be called  Reimand 
在2007-04-19,"张凤丽" <zhangfenglisdu@xxxxxxxxx> 写道:
hi,
i did  it that just because  i wanted myfun could be call when click a pushbutton. if i implement it in the paintEvent(), how to connect it with
the pushbutton? or the paintEvent() will be called automaticlly?
regards
fengli
2007/4/18, 张凤丽 <zhangfenglisdu@xxxxxxxxx>:Hi, friends
i do it like this, check for me.
maybe it looks stupid. if remeber well, i think it should be implement in the paintEvent(QPaintEvent *event) vitual function.
void MainWindow::myfun()
{
      ...
      QFrame *threeDPlotFrame;
      QPainter p(threeDPlotFrame);
      p.begin();
      drawLine(int, int , int, int);
       ...
      p.end();    
}
regards
fengli
2007/4/18, 张凤丽 <zhangfenglisdu@xxxxxxxxx>:hi, guys
i am making a gui for a cnc system by qt. now i want to draw the motion path of the machine tools.
i want to ask , is it possible to draw sth ( a line, for example) in one of my function not in the paintEvent(QPaintEvent *event) vitual function?
regards
fengli