qt5 creator + designer: super simple graphic examples
hallo,
ich habe z.Zt nur sehr simple qt5 creator GUI Programme mit wenigen Buttons und beschrifteten Labels, z.B.
https://github.com/dsyleixa/Raspberr...p_ads1115.jpeg
Nun möchte ich einen Zeichnungs-Bereich (eine Leinwand) in die Form einfügen, in dem ich per Programmcode Linien- und Formgrafiken anzeigen kann.
In der Vielzahl der widgets für den qt Designer finde ich aber nichts, was man da in der Form als Leinwand einfügen und zur passenden Größe"aufziehen" kann.
Was nimmt man da?
Als nächstes möchte ich (zum Üben) ein einfaches Quadrat (outline) und einen Kreis (fillshape) platzieren, in der Art
SetBackgound(BLACK);
SetColor(RED);
RectOutline(20, 20, 40, 40);
SetColor(YELLOW);
Circle(30, 24, 10);
wie mache ich das mit welchem qt-Code in dem soeben in die Form eingefügten Paint-Bereich?
Liste der Anhänge anzeigen (Anzahl: 1)
mainwindow.ui
Code:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>474</width>
<height>411</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralWidget">
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>180</x>
<y>300</y>
<width>101</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>Quit</string>
</property>
</widget>
<widget class="MyWidget" name="widget" native="true">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>451</width>
<height>271</height>
</rect>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>474</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<widget class="QStatusBar" name="statusBar"/>
<widget class="QToolBar" name="toolBar">
<property name="windowTitle">
<string>toolBar</string>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<action name="action">
<property name="text">
<string/>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>MyWidget</class>
<extends>QWidget</extends>
<header>mywidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>pushButton</sender>
<signal>clicked()</signal>
<receiver>MainWindow</receiver>
<slot>close()</slot>
<hints>
<hint type="sourcelabel">
<x>234</x>
<y>171</y>
</hint>
<hint type="destinationlabel">
<x>260</x>
<y>229</y>
</hint>
</hints>
</connection>
</connections>
</ui>
qt_btn_paint.pro
Code:
#-------------------------------------------------
#
# Project created by QtCreator 2019-09-16T12:09:00
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = GUI_app
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += main.cpp\
mainwindow.cpp \
mywidget.cpp
HEADERS += mainwindow.h \
mywidget.h
FORMS += mainwindow.ui
- - - Aktualisiert - - -