Graphics classes troubles...
-
- I have an inherited class QGraphicsView and implemented paintEvent, why does debugger write: QPainter::begin: Paint device returned engine == 0, type: 1 ??
This is whole code:
@void GraphicsView::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.setBrush(QBrush(QColor(255,127,0)));
painter.drawRect(this->sceneRect());
}@
And I am not drawing outside from paintEvent method. - Why I have scollbars in my GraphicsView window ? How to remove them?
- I have an inherited class QGraphicsView and implemented paintEvent, why does debugger write: QPainter::begin: Paint device returned engine == 0, type: 1 ??
-
[quote author="Peppy" date="1304202309"]2. Why I have scollbars in my GraphicsView window ? How to remove them?[/quote]
"QGraphicsView":http://doc.qt.nokia.com/latest/qgraphicsview.html inherits "QAbstractScrollArea":http://doc.qt.nokia.com/latest/qabstractscrollarea.html so you can permanently disable the scrollbars by calling the following methods (please note the arguments):
@setVerticalScrollBarPolicy ( Qt::ScrollBarAlwaysOff );
setHorizontalScrollBarPolicy ( Qt::ScrollBarAlwaysOff );@Best regards,
Leon -
[quote author="Peppy" date="1304202756"]Thanks, and my first problem? What do you think?[/quote]
Honestly I did not understand what exactly is the problem. Btw what are you trying to achieve?
If you want just to set a background color it would be easier to use:
@setStyleSheet("background-color:rgb(255,127,0);");@
QGraphicsView inherits QAbstractScrollArea, which inherits QFrame, which inherits QWidget so you should be able to call setStyleSheet :)
Cheers,
Leon -
I have this code:
@
QGraphicScene scene;
scene.addRect(QRect(0,0,1000,700));GraphicsView gv(&scene);
gv.show();
@
And GraphicView class:
@
class GraphicsView : public QGraphicsView
{
public:
explicit GraphicsView(QGraphicsScene* scene) : QGraphicsView(scene) { }protected:
void paintEvent(QPaintEvent*);
};
void GraphicsView::paintEvent(QPaintEvent*)
{
QPainter painter(this);
painter.setBrush(QBrush(QColor(255,127,0)));
painter.drawRect(this->sceneRect());
}
@
Problem is, that debugger writes messages as I wrote above, and it doesn't draw anything.... -
Please check "this thread at stackoverflow":http://stackoverflow.com/questions/1117847/qt-4-5-how-do-i-get-a-qpainter-device-in-a-qgraphicsview the proposed solution is to use "viewport()":http://doc.qt.nokia.com/latest/qabstractscrollarea.html#viewport instead of this:
@QPainter painter(viewport());@
Best regards,
Leon -
Cool :) So now both issues are solved thanks to the viewport!
-
[quote author="Peppy" date="1304204584"]Yes, but this important thing should be in docs, I think. :)[/quote]
You can add a wiki howto article about this issue here at Qt Developer network :)
-
You can also reimplement "QGraphicsScene::drawBackground":http://doc.qt.nokia.com/latest/qgraphicsscene.html#drawBackground
or take a look also at "backgroundBrush":http://doc.qt.nokia.com/latest/qgraphicsscene.html#backgroundBrush-prop
regards
-
yes :)
you can reimplement drawbackground like this:@void GraphicsView::drawBackground(QPainter *painter,
const QRectF &f)
{
Q_UNUSED(f);
QRectF rect;
rect=this->mapToScene(0,0, this->width(), this->height()).boundingRect();
painter->fillRect( rect, QColor(255,127,0));
}@ -
[quote author="Peppy" date="1304204584"]Yes, but this important thing should be in docs, I think. :)[/quote]
QGV inherits QAbstractScrollArea and the docs there tell you all about the distinction between the viewport and the scroll area. Always a good idea to read the docs for the class(es) that the class of interest publically inherits too.