I hope someone finds the time to answer my C++ beginner question!
I `designed' a new class around the QPixMap like this:
{
private:
int m_x;
int m_y;
public:
Image
( const QString &filename,
int x,
int y
);
};
class Image : public QPixmap
{
private:
int m_x;
int m_y;
QString m_fileName;
public:
Image( const QString &filename, int x, int y );
};
To copy to clipboard, switch view to plain text mode
It only adds some new properties to the class.
Then I wrote another class that contains a list of these classes
{
Q_OBJECT
private:
QList<Image *> m_imageList;
public:
...
protected:
};
class Map : public QWidget
{
Q_OBJECT
private:
QList<Image *> m_imageList;
public:
Map( QWidget *parent=0 );
...
protected:
void paintEvent(QPaintEvent*);
};
To copy to clipboard, switch view to plain text mode
In the paintEvent function I want to draw the Images to the screen but I don't know how to do that How can I use the drawPixmap function to draw the pixmap in the Image class??
This is my (erronous) code to drawthe first image
{
if(m_imageList.count() > 0){
p.save();
p.drawPixmap( 0, 0, m_imageList.first()); <= ERROR
p.restore();
}
}
void Map::paintEvent(QPaintEvent*)
{
if(m_imageList.count() > 0){
QPainter p( this );
p.save();
p.drawPixmap( 0, 0, m_imageList.first()); <= ERROR
p.restore();
}
}
To copy to clipboard, switch view to plain text mode
Could I just cast the Image to a Pixmap class? And if so, how?
Thanks in advance.. the inheritance options in C++ still confuse me
Bookmarks