Results 1 to 4 of 4

Thread: Problem with my object inherited from QGraphicsPixmapItem

  1. #1
    Join Date
    Feb 2014
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    1

    Default Problem with my object inherited from QGraphicsPixmapItem

    Hi there,

    I'm just a newbie with Qt and I can t do a proper object inheritance with Qt. I'm trying to do a Frogger. My part is about the cars. However I try to do a vehicle class from a public QGraphicsPixmapItem but I can 't do it, it doesn't appear in the scene.


    My class vehicule.h
    class Vehicule : public QObject, public QGraphicsPixmapItem
    {
    Q_OBJECT
    public:
    Vehicule(const QPixmap &pix, QGraphicsItem *parent = 0);

    QRectF boundingRect() const;


    protected:
    void advance(int step);

    private:
    QPixmap Skin;
    };

    My vehicule.cpp
    #include "vehicule.h"

    #include <QGraphicsScene>
    #include <QGraphicsPixmapItem>
    #include <QStyleOption>

    #include <math.h>

    //! [0]
    Vehicule::Vehicule(const QPixmap &pix, QGraphicsItem *parent): QGraphicsPixmapItem(parent)
    {
    Skin = pix;
    }
    //! [0]
    //! [1]
    QRectF Vehicule::boundingRect() const
    {
    qreal adjust = 0.5;
    return QRectF(-18 - adjust, -22 - adjust,
    36 + adjust, 60 + adjust);
    }
    Part of my main.cpp
    //VEHICULE
    QPixmap WinM((":/images/windower.jpg"));

    Vehicule *win = new Vehicule(WinM);
    win->setZValue(1);
    scene.addItem(win);

    return a.exec();

    Thank you for your help

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Problem with my object inherited from QGraphicsPixmapItem

    Is WinM.isNull() == false?
    Your Vehicule constructor code does not pass the QPixmap on to the underlying QGraphicsPixmapItem constructor.

  3. #3
    Join Date
    Feb 2014
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    1

    Default Re: Problem with my object inherited from QGraphicsPixmapItem

    Hi there,

    No why should I make WinM.isNull() == false?
    Now my constructor looks like.

    Vehicule::Vehicule(const QPixmap &pix, QGraphicsItem *parent): QGraphicsPixmapItem(pix,parent)
    {
    Skin = pix;
    }
    but still invisible in my scene.
    Regards


    Added after 33 minutes:


    I don't understand now it's working. And I did not change my code oO.
    damned and thank by the way
    Last edited by firebeard6666; 20th February 2014 at 15:07.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Problem with my object inherited from QGraphicsPixmapItem

    Quote Originally Posted by firebeard6666 View Post
    No why should I make WinM.isNull() == false?
    If WinM.isNull() is true then your pixmap was not successfully loaded and will not display. That is why you would check (not set) the value.

  5. The following user says thank you to ChrisW67 for this useful post:

    firebeard6666 (23rd February 2014)

Similar Threads

  1. Replies: 4
    Last Post: 2nd October 2012, 18:39
  2. problem with Qgraphicspixmapitem
    By skab in forum Newbie
    Replies: 3
    Last Post: 23rd October 2010, 10:54
  3. Replies: 3
    Last Post: 22nd August 2010, 10:23
  4. Inherited Palette Problem
    By zgulser in forum Qt Programming
    Replies: 7
    Last Post: 10th March 2010, 11:09
  5. basic inherited or vector problem?
    By mickey in forum General Programming
    Replies: 8
    Last Post: 14th February 2007, 21:29

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
  •  
Qt is a trademark of The Qt Company.