Вы находитесь на странице: 1из 101

http://www.qt.

io/download-open-source/

http://woboq.com/blog/how-qt-signals-slots-work.html

If you want to use images, you need to new a resource file.

650
(0,0)

444

You should create a Snoopy class first.

Choose QWidget class to inherit it.

(0,0)
400

230

210

210

(0,220)

To repaint window view so that Snoopy looks like really moving!


We will use QTimer class to realize it~

way1:
change image position in
a fixed size widget.

way2:
move whole widget in the
main window.

way1 v.s way2


way1 is better

way2 is better

way1: change image position in a fixed size widget

way1: change image position in a fixed size widget

way1: change image position in a fixed size widget


connect
update()

way1:change image position in a fixed size widget

way2: move whole widget in the main window

way2: move whole widget in the main window


2.1

way2: move whole widget in the main window

way2: move whole widget in the main window

way2: move whole widget in the main window


snoopyAction()
snoopyAction()

way2: move whole widget in the main window

move(x,y)

Click up
button

event
event

event
event

http://doc.qt.io/qt-5/qmediaplayer.html

What is widget?
widget

QWidget

key

mouse

QObject

signals
slots
connect() function in QObject
connect(sender, SIGNAL(signal), receiver, SLOT(slot));
http://qt-project.org/doc/qt-4.8/qobject.html#details

Connect function under QObject class

QWidget

QWidget

http://qt-project.org/doc/qt-4.8/qwidget.html

Public

QWidget

setFixedSize
move
setWindowIcon

33 public functions inherited from QObject


15 public functions inherited from QPaintDevice

Public Slots QWidget


close
update

//Closes this widget.


//Updates the widget unless updates are disabled or
the widget is hidden.

show

//Shows the widget and its child widgets.

Protected

QWidget

paintEvent (
keyPressEvent
mousePressEvent
keyReleaseEvent
mouseReleaseEvent
mouseMoveEvent

QMainWindow

QToolBars
QDockWidgets

QMenuBar

QStatusBar

http://qtproject.org/doc/qt4.8/qmainwindow.html#details

QMainWindow

Public

QMainWindow

menuBar
addToolBar
addDockWidget
statusBar

212 public functions inherited from QWidget


33 public functions inherited from QObject
15 public functions inherited from QPaintDevice

Вам также может понравиться