I'm new to Qt and started developing an app based on one of the sample projects qt provides: "Image Viewer".
Here's the examle project itself: http://doc.qt.io/qt-4.8/qt-widgets-imageviewer-example.html
To make sure I didn't do anything wrong thying to extend project's functionality, I created a new project and simply copied files from example project (see section "Files" at the top of "Image Viewer Example" page)
Then, I edited imageviewer.h file:
added
#include <QPainter>
and
protected:
void paintEvent(QPaintEvent *);
to ImageViewer class.
Then I defined paintEvent in imageviewe.cpp:
void ImageViewer::paintEvent(QPaintEvent * e)
{
QPainter p(this);
p.drawLine(0,0,100,100);
}
I expected that to draw a line in the top-left corner, but it didn't.
It seems to me, that the point is that scrollArea overlaps the line, making it "invisible". So, I commented out the line
setCentralWidget(scrollArea);
within ImageViewer::ImageViewer() definition.
The line appeared, but the images were not showed, of coruse.
Then I tried drawing on scrollArea itself, changing paintEvent code:
void ImageViewer::paintEvent(QPaintEvent * e)
{
QPainter p(scrollArea);
p.drawLine(0,0,100,100);
}
which resulted in messages like
QPainter::begin: Paint device returned engine == 0, type: 1
Tried googling it, but the solutions have nothing to do with scrollArea overlapping the line (or just don't work).
Would appreciate any help on this.