Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] How correctly inherit from QGraphicsPixmapItem?
Forum Update on Monday, May 27th 2025

[Solved] How correctly inherit from QGraphicsPixmapItem?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.2k Views
  • 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 Offline
    G Offline
    gerberka
    wrote on last edited by
    #1

    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
    0
    • C Offline
      C Offline
      chrisaverage
      wrote on last edited by
      #2

      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
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved