Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    [Solved] How correctly inherit from QGraphicsPixmapItem?

    General and Desktop
    2
    2
    1041
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • G
      gerberka last edited by

      Compiler show error:
      C:\Qt\Examples\Qt-5.3\widgets\widgets\imageviewer\debug\moc_imageitem.cpp:71: ошибка: invalid static_cast from type 'QObject*' to type 'ImageItem*'
      ImageItem *_t = static_cast<ImageItem *>(_o);

      What I do wrong?

      "imageitem.h"
      @#ifndef IMAGEITEM_H
      #define IMAGEITEM_H

      #include <QGraphicsPixmapItem>

      class ImageItem : public QGraphicsPixmapItem
      {
      Q_OBJECT
      public:
      ImageItem(QPixmap pixmap) : QGraphicsPixmapItem(pixmap){}

      public slots:
      void changeVisibility(int state){
      if(state == 0)hide();
      else show();
      }
      void changeOpacity(int level){
      setOpacity(level/10);
      }
      };

      #endif // IMAGEITEM_H@

      1 Reply Last reply Reply Quote 0
      • C
        chrisaverage last edited by

        QGraphicsPixmapItem does not inherit QObject so macro Q_OBJECT is incorrect here. If you need it to be QObject too then you need to inherit QObject explicitly.

        1 Reply Last reply Reply Quote 0
        • First post
          Last post