Qt 4.6.0 (SDK for Windows with MinGW)
Hello!
Here is the minimum example:
mainwindow.cpp :
#include <QGraphicsView>
#include "mainwindow.h"
#include "myscene.h"
MainWindow
::MainWindow(QWidget *parent
){
MyScene* s = new MyScene(this);
s->setSceneRect(-1000,-1000,3000,3000);
setCentralWidget(v);
}
#include <QGraphicsView>
#include "mainwindow.h"
#include "myscene.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
MyScene* s = new MyScene(this);
s->setSceneRect(-1000,-1000,3000,3000);
QGraphicsView* v = new QGraphicsView(s);
setCentralWidget(v);
}
To copy to clipboard, switch view to plain text mode
myscene.cpp:
#include <QGraphicsEllipseItem>
#include <QGraphicsSceneMouseEvent>
#include "myscene.h"
MyScene
::MyScene(QObject *parent
) :{
}
{
QRectF circleRect
(0,
0,
600,
600);
circleRect.moveCenter(e->scenePos());
el
->setPen
(QPen(Qt
::red,
4, Qt
::DashLine));
addItem(el);
}
#include <QGraphicsEllipseItem>
#include <QGraphicsSceneMouseEvent>
#include "myscene.h"
MyScene::MyScene(QObject *parent) :
QGraphicsScene(parent)
{
}
void MyScene::mouseDoubleClickEvent ( QGraphicsSceneMouseEvent * e )
{
QRectF circleRect(0,0,600,600);
circleRect.moveCenter(e->scenePos());
QGraphicsEllipseItem* el = new QGraphicsEllipseItem(circleRect);
el->setPen(QPen(Qt::red, 4, Qt::DashLine));
addItem(el);
}
To copy to clipboard, switch view to plain text mode
main.cpp, myscene.h and mainwindow.h are the default as generated by QtCreator (except that I added mouseDoubleClickEvent declaration to myscene.h).
When I double click in the corner of the view, the ellipse appears (Only part of it fits in the view and that's OK), and when I scroll the view to the right, I see this:
If I use Qt::SolidLine, everything is fine, but with Qt:ashLine and all other styles I see this painting artefact.
Thanks in advance.
Bookmarks