View Full Version : Graphics without qwt
maider
17th June 2009, 14:37
I want do a graphic that plot some bars or rects into two axys, x and y.
I can not use qwt due to I have to do everything step by step.
Does anyone can help me?
shentian
17th June 2009, 15:11
Have a look at QGraphicsView and QGraphicsScene. Using QGraphicsRectItem you should be able to draw a bar plot with a few lines of code...
Lykurg
17th June 2009, 15:27
...or if the drawings are simple, just use a QWidget and do custom painting in QWidget::paintEvent()
maider
19th June 2009, 14:44
I have get the lines, but how can I do the axes?i have tryed doing with drawLine() but they don't see.The code of the lines is the following one:
Brush::Brush(QWidget *parent)
: QWidget(parent)
{
}
void Brush::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.setPen(Qt::NoPen);
QPen pen(Qt::black,2);
painter.drawLine(100, 100, 75, 225);
painter.setBrush(Qt::VerPattern);
painter.drawRect(100, 100, 600,200);
}
You have NoPen setting.. change to:
void Brush::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
QPen pen = painter.pen();
pen.setColor( Qt::black );
painter.setPen( pen );
painter.drawLine(100, 100, 75, 225);
painter.setBrush(Qt::VerPattern);
painter.drawRect(100, 100, 600,200);
}
maider
22nd June 2009, 07:22
I have done as you tell me but the shape that it is drawn is not what I need.
I need to paint the "axe t" and the "axe y" that I have added to the picture.
how can I do the axes?
maider
22nd June 2009, 10:22
what I am doing wrong?
I'm trying with QGraphicsLineItem but i don't get it!:confused:
My new code is:
Brush::Brush(QWidget *parent)
: QWidget(parent)
{
}
void Brush::paintEvent(QPaintEvent *event)
{
QGraphicsScene *scene1 = new QGraphicsScene(this);
int x1, y1, x2, y2, t;
x1 = 0; y1=0; x2=100; y2=2, t=0;
QPainter painter(this);
painter.setPen(Qt::NoPen);
QPen pen(Qt::black,2);
painter.drawLine(100, 100, 75, 225);
painter.setBrush(Qt::VerPattern);
painter.drawRect(100, 100, 600,200);
QGraphicsLineItem *line = new QGraphicsLineItem( QLineF( x1,y1, x2, y2 ) );
scene1->addItem(line);
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.