How to overwrite a Widget?
-
Hi,
I want to create my own QGraphicsView so I created a CustomView that extends QGraphicsView, added a GraphicsView to my .ui and promoted it to use my CustomView
but I can't compile with the exception:In file included from /home/edu/uni/psys22-projekt/src/ui/dialog.cpp:2: /home/edu/uni/projekt/cmake-build-debug/src/projekt_autogen/include/./ui_dialog.h:18:10: fatal error: CustomView.h: No such file or directory 18 | #include "CustomView.h" | ^~~~~~~~~~~~~~
But if I open ui_dialog.h it has the include and the IDE shows no errors even the link works properly (ctrl + left click):
So I don't know what I am doing wrong here.
All my ui files are in the same dir:
and added to cmakefile:
#include <QGraphicsView> #include <QtWidgets> #include <QWidget> class CustomView : public QGraphicsView { public: explicit CustomView(QWidget* parent = nullptr); protected: virtual void wheelEvent(QWheelEvent *event); };
#include "CustomView.h" CustomView::CustomView(QWidget *parent) : QGraphicsView(parent) { } void CustomView::wheelEvent(QWheelEvent *event) { setTransformationAnchor(QGraphicsView::AnchorUnderMouse); double scaleFactor = 1.15; if (event->angleDelta().y() > 0) { scale(scaleFactor, scaleFactor); } else { scale(1/scaleFactor, 1/scaleFactor); } }
<?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>Dialog</class> <widget class="QDialog" name="Dialog"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>821</width> <height>617</height> </rect> </property> <property name="sizePolicy"> <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> <property name="windowTitle"> <string>Dialog</string> </property> <widget class="QPushButton" name="runButton"> <property name="geometry"> <rect> <x>700</x> <y>40</y> <width>89</width> <height>25</height> </rect> </property> <property name="text"> <string>run</string> </property> </widget> <widget class="CustomView" name="customView"> <property name="geometry"> <rect> <x>0</x> <y>80</y> <width>821</width> <height>541</height> </rect> </property> <property name="sizeIncrement"> <size> <width>100</width> <height>100</height> </size> </property> </widget> <widget class="QPushButton" name="resetButton"> <property name="geometry"> <rect> <x>700</x> <y>10</y> <width>89</width> <height>25</height> </rect> </property> <property name="text"> <string>reset</string> </property> </widget> <widget class="QSpinBox" name="spinBox"> <property name="geometry"> <rect> <x>610</x> <y>40</y> <width>81</width> <height>26</height> </rect> </property> <property name="maximum"> <number>10</number> </property> <property name="singleStep"> <number>1</number> </property> <property name="value"> <number>10</number> </property> </widget> <widget class="QLabel" name="label"> <property name="geometry"> <rect> <x>630</x> <y>20</y> <width>67</width> <height>17</height> </rect> </property> <property name="text"> <string>sleep</string> </property> </widget> <widget class="QPushButton" name="openFile"> <property name="geometry"> <rect> <x>10</x> <y>40</y> <width>89</width> <height>25</height> </rect> </property> <property name="text"> <string>files</string> </property> </widget> <widget class="QLabel" name="label_2"> <property name="geometry"> <rect> <x>20</x> <y>20</y> <width>67</width> <height>17</height> </rect> </property> <property name="text"> <string>Load data</string> </property> </widget> </widget> <customwidgets> <customwidget> <class>CustomView</class> <extends>QGraphicsView</extends> <header>CustomView.h</header> </customwidget> </customwidgets> <resources/> <connections/> </ui>
-
You have to add the directory which contains CustomView.h to your target with target_include_directories()