Qt 5.10 Book Examples
chapter19
Window
main.cpp
Go to the documentation of this file.
1
// ======================================================================
2
// main.cpp
3
// ======================================================================
4
// This file is a part of the book
5
// "Qt 5.10 Professional programming with C++"
6
// http://qt-book.com
7
// ======================================================================
8
// Copyright (c) 2017 by Max Schlee
9
// ======================================================================
10
11
#include <QtWidgets>
12
13
// ======================================================================
14
class
Window
:
public
QLabel {
15
private
:
16
QPoint m_ptPosition;
17
18
protected
:
19
virtual
void
mousePressEvent
(QMouseEvent* pe)
20
{
21
m_ptPosition = pe->pos();
22
}
23
24
virtual
void
mouseMoveEvent
(QMouseEvent* pe)
25
{
26
move(pe->globalPos() - m_ptPosition);
27
}
28
29
public
:
30
Window
(QWidget* pwgt = 0)
31
: QLabel(pwgt, Qt::FramelessWindowHint | Qt::
Window
)
32
{
33
}
34
};
35
36
// ----------------------------------------------------------------------
37
int
main
(
int
argc,
char
** argv)
38
{
39
QApplication app(argc, argv);
40
Window
wnd;
41
42
wnd.setAttribute(Qt::WA_TranslucentBackground);
43
wnd.setPixmap(QPixmap(
":/happyos.png"
));
44
45
QPushButton* pcmdQuit =
new
QPushButton(
"X"
);
46
pcmdQuit->setFixedSize(16, 16);
47
QObject::connect(pcmdQuit, SIGNAL(clicked()), &app, SLOT(quit()));
48
49
//setup layout
50
QVBoxLayout* pvbx =
new
QVBoxLayout;
51
pvbx->addWidget(pcmdQuit);
52
pvbx->addStretch(1);
53
wnd.setLayout(pvbx);
54
55
wnd.show();
56
57
return
app.exec();
58
}
Window
Definition:
main.cpp:14
Window::Window
Window(QWidget *pwgt=0)
Definition:
main.cpp:30
Window::mousePressEvent
virtual void mousePressEvent(QMouseEvent *pe)
Definition:
main.cpp:19
main
int main(int argc, char **argv)
Definition:
main.cpp:15
Window::mouseMoveEvent
virtual void mouseMoveEvent(QMouseEvent *pe)
Definition:
main.cpp:24
Generated by
1.8.14