C++ (Qt)void MyWidget::paintEvent(){ QPainter paint(this); paint.drawPoint(0, 0); paint.translate(100.0, 40.0); paint.drawPoint(-100, -40);}
GraphWidget::GraphWidget( int h, int w, QWidget * parent ) : QWidget( parent ), width( w ), height( h ){ buf = new QPixmap( width, height ); buf->fill( Qt::white );}
MainWindow::MainWindow(QWidget * parent) : QMainWindow( parent ){ graphWidget = new GraphWidget( qApp->desktop()->height() + 1000, qApp->desktop()->width() + 1000, this ); CreateActions(); CreateMenus(); QScrollArea * areaScroll = new QScrollArea; areaScroll->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOn ); areaScroll->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOn ); areaScroll->setWidget( graphWidget ); CreateToolbars(); QHBoxLayout *centralLayout = new QHBoxLayout; centralLayout->addWidget( areaScroll ); QWidget *mainWidget = new QWidget; mainWidget->setLayout( centralLayout ); setCentralWidget( mainWidget );}
void GraphCurve::PaintCurve( MbCurve * curve, QPixmap * buf, const QColor & col1, const QColor & col2 ){ QPainter painter; QPainterPath path; MbCartPoint point; vector< double > param; double tMin, tMax; painter.begin( buf ); painter.setPen( QPen(col1, 5) ); tMin = curve->GetMinValueParameter(); tMax = curve->GetMaxValueParameter(); curve->StepParameter( tMin, tMax, param ); curve->CalcPointCurve( param[0], point ); path.moveTo( point.x, point.y ); painter.setPen( col2 ); for( vector< double >::iterator i = param.begin() + 1; i != param.end(); ++i) { curve->CalcPointCurve( *i, point ); path.lineTo( point.x, point.y ); } painter.drawPath( path ); painter.end();}
C++ (Qt)graphWidget = new GraphWidget( qApp->desktop()->height() + 1000, qApp->desktop()->width() + 1000, this );