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. How to overwrite a Widget?
Forum Updated to NodeBB v4.3 + New Features

How to overwrite a Widget?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 127 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.
  • H Offline
    H Offline
    HoliGui
    wrote on last edited by
    #1

    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):
    14288c90-b182-447c-9b5b-57cdf250a37f-image.png

    So I don't know what I am doing wrong here.

    All my ui files are in the same dir:
    af2ec4b0-dbab-4a96-a3bf-73089662b8aa-image.png
    and added to cmakefile:
    8badb75c-6f01-414e-8b4c-eef792e2db60-image.png

    #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>
    
    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      You have to add the directory which contains CustomView.h to your target with target_include_directories()

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1

      • Login

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