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. QGraphicsView Inheritance
Forum Updated to NodeBB v4.3 + New Features

QGraphicsView Inheritance

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.8k Views 1 Watching
  • 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.
  • Akito_KamiA Offline
    Akito_KamiA Offline
    Akito_Kami
    wrote on last edited by
    #1

    I am trying to implement a mouse scroll zoom function as a child class for QGraphicsView.
    When compiling I get the error: " error C2247: 'QObject::setObjectName' not accessible because 'CustomGraphicsView' uses 'private' to inherit from 'QGraphicsView'".

    This occurs for every function call from QGraphicsView.

    I used QtCreator's promote to to change my qgraphicsview to my customgraphicsview class.
    My code is as follows:

    customgraphicsview.h

    #ifndef CUSTOMGRAPHICSVIEW_H
    #define CUSTOMGRAPHICSVIEW_H
    
    #include <QGraphicsView>
    #include <QtWidgets>
    #include <QWidget>
    
    class CustomGraphicsView : QGraphicsView
    {
    public:
        CustomGraphicsView(QWidget* parent = 0);
    
    protected:
        virtual void wheelEvent(QWheelEvent *event);
    private:
        const double scaleFactor = 1.2
    };
    
    #endif // CUSTOMGRAPHICSVIEW_H
    
    

    customgraphicsview.cpp

    #include "customgraphicsview.h"
    
    CustomGraphicsView::CustomGraphicsView(QWidget *parent) : QGraphicsView(parent)
    {
    
    }
    
    void CustomGraphicsView::wheelEvent(QWheelEvent *event)
    {
        setTransformationAnchor(QGraphicsView::AnchorViewCenter);
        if (event->delta() > 0) {
            scale(scaleFactor, scaleFactor);
        } else {
            scale(1/scaleFactor, 1/scaleFactor);
        }
    }
    
    

    I am currently on Qt 5.7 using MSVC.

    1 Reply Last reply
    0
    • sneubertS Offline
      sneubertS Offline
      sneubert
      wrote on last edited by
      #2

      change inheritance to public:

      class CustomGraphicsView : public QGraphicsView

      1 Reply Last reply
      3

      • Login

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