Created
September 20, 2017 16:24
-
-
Save eyllanesc/2d9e8ae64edade4d4090cba92819e000 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "frame.h" | |
#include <QPainter> | |
frame::frame(QWidget *parent) : QFrame(parent) | |
{ | |
} | |
void frame::paintEvent(QPaintEvent *p) | |
{ | |
QPainter pPainter(this); | |
QImage img(":/left.png"); | |
Q_ASSERT(!img.isNull()); | |
QRect source(0,0,20,10); | |
QRect target(50,50,20,10); | |
pPainter.drawImage(target, img, source); | |
QWidget::paintEvent(p); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef FRAME_H | |
#define FRAME_H | |
#include <QFrame> | |
class frame : public QFrame | |
{ | |
Q_OBJECT | |
public: | |
explicit frame(QWidget *parent = nullptr); | |
protected: | |
void paintEvent(QPaintEvent *p); | |
}; | |
#endif // FRAME_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "widget.h" | |
#include <QApplication> | |
int main(int argc, char *argv[]) | |
{ | |
QApplication a(argc, argv); | |
Widget w; | |
w.show(); | |
return a.exec(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<RCC> | |
<qresource prefix="/"> | |
<file>left.png</file> | |
</qresource> | |
</RCC> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#------------------------------------------------- | |
# | |
# Project created by QtCreator 2017-09-20T10:41:49 | |
# | |
#------------------------------------------------- | |
QT += core gui | |
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets | |
TARGET = testImage | |
TEMPLATE = app | |
# The following define makes your compiler emit warnings if you use | |
# any feature of Qt which has 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 \ | |
widget.cpp \ | |
frame.cpp | |
HEADERS += \ | |
widget.h \ | |
frame.h | |
FORMS += \ | |
widget.ui | |
RESOURCES += \ | |
resource.qrc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "widget.h" | |
#include "ui_widget.h" | |
Widget::Widget(QWidget *parent) : | |
QFrame(parent), | |
ui(new Ui::Widget) | |
{ | |
ui->setupUi(this); | |
} | |
Widget::~Widget() | |
{ | |
delete ui; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef WIDGET_H | |
#define WIDGET_H | |
#include "frame.h" | |
#include <QWidget> | |
namespace Ui { | |
class Widget; | |
} | |
class Widget : public QFrame | |
{ | |
Q_OBJECT | |
public: | |
explicit Widget(QWidget *parent = 0); | |
~Widget(); | |
private: | |
Ui::Widget *ui; | |
}; | |
#endif // WIDGET_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<ui version="4.0"> | |
<class>Widget</class> | |
<widget class="QWidget" name="Widget"> | |
<property name="geometry"> | |
<rect> | |
<x>0</x> | |
<y>0</y> | |
<width>823</width> | |
<height>468</height> | |
</rect> | |
</property> | |
<property name="windowTitle"> | |
<string>Widget</string> | |
</property> | |
<widget class="frame" name="myFrame"> | |
<property name="geometry"> | |
<rect> | |
<x>200</x> | |
<y>60</y> | |
<width>420</width> | |
<height>300</height> | |
</rect> | |
</property> | |
<property name="minimumSize"> | |
<size> | |
<width>420</width> | |
<height>300</height> | |
</size> | |
</property> | |
<property name="maximumSize"> | |
<size> | |
<width>420</width> | |
<height>306</height> | |
</size> | |
</property> | |
<property name="frameShape"> | |
<enum>QFrame::StyledPanel</enum> | |
</property> | |
<property name="frameShadow"> | |
<enum>QFrame::Raised</enum> | |
</property> | |
</widget> | |
</widget> | |
<layoutdefault spacing="6" margin="11"/> | |
<customwidgets> | |
<customwidget> | |
<class>frame</class> | |
<extends>QFrame</extends> | |
<header>frame.h</header> | |
<container>1</container> | |
</customwidget> | |
</customwidgets> | |
<resources/> | |
<connections/> | |
</ui> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment