Thank you for your interest!
I've ridden docs and I know about that. Let's say I have QGraphicsScene with 200x200px size. Window size (and QGraphicsView size) is about 1000x1000. Then I draw QGraphicsTextItem with string with at least 1000 chars. and draw it at (0,0) point. Unfortunatelly it is always! drawn on whole window (1000x1000) and it is not cropped to 200x200px. Moreover if I enable dragging of this text item I am able to move them on whole window - not only on 200x200px scene.
Let me show you my code. Maybe I'm doing sth wrong and I can't see it.
Methods of my QGraphicsView class:
m_canvas(0)
{
setupGUI();
}
Scene
::Scene(Canvas
* canvas,
QWidget *parent
) : m_canvas(canvas)
{
setupGUI();
}
Scene::~Scene()
{
closeCanvas();
}
void Scene::setupGUI()
{
this->setAutoFillBackground(false);
this->viewport()->setAutoFillBackground(false);
}
void Scene
::newCanvas(const QRectF & dimension
) {
closeCanvas();
m_canvas = new Canvas(dimension, this);
this->setScene(m_canvas);
}
void Scene::closeCanvas()
{
if (m_canvas)
{
delete m_canvas;
m_canvas = 0;
}
}
{
double scaleFactor = 1.05;
if (event->modifiers() & Qt::ControlModifier)
scaleFactor += 0.3;
if(event->delta() < 0)
scaleFactor = 1.0 / scaleFactor;
scale(scaleFactor, scaleFactor);
centerOn( mapToScene(event->pos()) );
}
Scene::Scene(QWidget *parent) :
QGraphicsView(parent),
m_canvas(0)
{
setupGUI();
}
Scene::Scene(Canvas * canvas, QWidget *parent) :
QGraphicsView(canvas, parent),
m_canvas(canvas)
{
setupGUI();
}
Scene::~Scene()
{
closeCanvas();
}
void Scene::setupGUI()
{
this->setAutoFillBackground(false);
this->viewport()->setAutoFillBackground(false);
}
void Scene::newCanvas(const QRectF & dimension)
{
closeCanvas();
m_canvas = new Canvas(dimension, this);
this->setScene(m_canvas);
}
void Scene::closeCanvas()
{
if (m_canvas)
{
delete m_canvas;
m_canvas = 0;
}
}
void Scene::wheelEvent(QWheelEvent* event)
{
double scaleFactor = 1.05;
if (event->modifiers() & Qt::ControlModifier)
scaleFactor += 0.3;
if(event->delta() < 0)
scaleFactor = 1.0 / scaleFactor;
scale(scaleFactor, scaleFactor);
centerOn( mapToScene(event->pos()) );
}
To copy to clipboard, switch view to plain text mode
Metho9ds of QGraphicsScene class:
{
QGraphicsDropShadowEffect * effect = new QGraphicsDropShadowEffect();
effect->setBlurRadius(20);
effect->setOffset(5);
background->setGraphicsEffect(effect);
background->setBrush(Qt::white);
}
{
QGraphicsScene::drawBackground(painter, rect.
intersect(this
->sceneRect
()));
}
{
QGraphicsScene::drawForeground(painter, rect.
intersect(this
->sceneRect
()));
}
Canvas::Canvas(const QRectF & dimension, QObject * parent) :
QGraphicsScene(dimension, parent)
{
QGraphicsRectItem * background = new QGraphicsRectItem(dimension,0,this);
QGraphicsDropShadowEffect * effect = new QGraphicsDropShadowEffect();
effect->setBlurRadius(20);
effect->setOffset(5);
background->setGraphicsEffect(effect);
background->setBrush(Qt::white);
QGraphicsTextItem * text = new QGraphicsTextItem("hudskjgifv j",0,this);
text->setFlag(QGraphicsItem::ItemIsMovable, true);
}
void Canvas::drawBackground(QPainter * painter, const QRectF & rect)
{
QGraphicsScene::drawBackground(painter, rect.intersect(this->sceneRect()));
}
void Canvas::drawForeground(QPainter * painter, const QRectF & rect)
{
QGraphicsScene::drawForeground(painter, rect.intersect(this->sceneRect()));
}
To copy to clipboard, switch view to plain text mode
And at last here is the code where I create my window:
KXmlGuiWindow * window = new KXmlGuiWindow();
Scene * m_scene = new Scene(window);
m_scene
->newCanvas
(QRectF(0,
0,
200.0,
200.0));
window->setCentralWidget(m_scene);
window->show();
KXmlGuiWindow * window = new KXmlGuiWindow();
Scene * m_scene = new Scene(window);
m_scene->newCanvas(QRectF(0, 0, 200.0, 200.0));
window->setCentralWidget(m_scene);
window->show();
To copy to clipboard, switch view to plain text mode
Bookmarks