Results 1 to 3 of 3

Thread: Beginner C++ question

  1. #1
    Join Date
    Apr 2006
    Location
    the netherlands
    Posts
    17
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Beginner C++ question

    I hope someone finds the time to answer my C++ beginner question!

    I `designed' a new class around the QPixMap like this:

    Qt Code:
    1. class Image : public QPixmap
    2. {
    3. private:
    4. int m_x;
    5. int m_y;
    6. QString m_fileName;
    7.  
    8. public:
    9. Image( const QString &filename, int x, int y );
    10.  
    11. };
    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
    Qt Code:
    1. class Map : public QWidget
    2. {
    3. Q_OBJECT
    4.  
    5. private:
    6. QList<Image *> m_imageList;
    7.  
    8. public:
    9. Map( QWidget *parent=0 );
    10. ...
    11. protected:
    12. void paintEvent(QPaintEvent*);
    13.  
    14. };
    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

    Qt Code:
    1. void Map::paintEvent(QPaintEvent*)
    2. {
    3. if(m_imageList.count() > 0){
    4. QPainter p( this );
    5. p.save();
    6. p.drawPixmap( 0, 0, m_imageList.first()); <= ERROR
    7. p.restore();
    8. }
    9. }
    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

  2. #2
    Join Date
    Apr 2006
    Location
    the netherlands
    Posts
    17
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Beginner C++ question

    sorry.. found the solution myself

    Qt Code:
    1. p.drawPixmap( 0, 0, *(dynamic_cast<QPixmap*>(m_imageList.first())));
    To copy to clipboard, switch view to plain text mode 

    not realy nice to read actualy

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Beginner C++ question

    IMO this should be enough:
    Qt Code:
    1. p.drawPixmap( 0, 0, *(m_imageList.first()));
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Plugin implementation question
    By JPNaude in forum Qt Programming
    Replies: 12
    Last Post: 27th August 2008, 21:24
  2. Useless but curious compiler warning question
    By Raccoon29 in forum General Programming
    Replies: 4
    Last Post: 30th July 2008, 21:46
  3. Exceptions / setjmp/longjmp question
    By Aceman2000 in forum Qt Programming
    Replies: 3
    Last Post: 13th March 2008, 18:14
  4. Access to QSqlTableModel::isDirty Question.
    By patrik08 in forum Qt Programming
    Replies: 3
    Last Post: 12th April 2007, 18:49

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.