Skip to content

Commit e66da66

Browse files
committed
新增 PyQT5代碼
1 parent c13751c commit e66da66

File tree

8 files changed

+576
-0
lines changed

8 files changed

+576
-0
lines changed

PyQT5/Chapter_1/main.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "mainwindow.h"
2+
#include <QApplication>
3+
4+
int main(int argc, char *argv[])
5+
{
6+
QApplication a(argc, argv);
7+
MainWindow w;
8+
w.show();
9+
10+
return a.exec();
11+
}

PyQT5/Chapter_1/main.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# Form implementation generated from reading ui file 'mainwindow.ui'
4+
#
5+
# Created by: PyQt5 UI code generator 5.10.1
6+
#
7+
# WARNING! All changes made in this file will be lost!
8+
9+
import sys
10+
import os
11+
import time
12+
import subprocess
13+
14+
from PyQt5 import QtCore, QtGui, QtWidgets
15+
from PyQt5.QtWidgets import QMainWindow, QApplication, QListView, QFileDialog
16+
from PyQt5.QtGui import QStandardItemModel, QStandardItem
17+
from PyQt5.QtCore import pyqtSlot
18+
19+
from mark_tool import Ui_MainWindow
20+
21+
class Mark(QMainWindow, Ui_MainWindow):
22+
23+
def __init__(self, parent=None):
24+
# 繼承Ui_MainWindow 也就是 mark_tool 內的 class
25+
super(Mark, self).__init__(parent)
26+
27+
# 建立ui介面
28+
self.setupUi(self)
29+
# 這功能主要是點擊了這個按鈕要執行什麼?
30+
# self.TestButton 這個 function 在 mark_tool.Ui_MainWindow內
31+
# 因為已經繼承了Ui_MainWindow,因此執行執行 self.TestButton
32+
# 點擊了時候會套用下方的function test_button_clicked,會將值輸出
33+
# 如果沒有這行,點擊按鈕不會有任何的東做
34+
self.TestButton.clicked.connect(self.test_button_clicked)
35+
36+
def test_button_clicked(self):
37+
print('test')
38+
39+
if __name__ == "__main__":
40+
41+
# 第一行必備,系統呼叫
42+
app = QApplication(sys.argv)
43+
44+
# 指定 Mark Class 會先執行__init__
45+
window = Mark()
46+
47+
# 將GUI介面顯示出來
48+
window.show()
49+
50+
# 關閉系統
51+
sys.exit(app.exec_())

PyQT5/Chapter_1/mainwindow.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include "mainwindow.h"
2+
#include "ui_mainwindow.h"
3+
4+
MainWindow::MainWindow(QWidget *parent) :
5+
QMainWindow(parent),
6+
ui(new Ui::MainWindow)
7+
{
8+
ui->setupUi(this);
9+
}
10+
11+
MainWindow::~MainWindow()
12+
{
13+
delete ui;
14+
}

PyQT5/Chapter_1/mainwindow.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef MAINWINDOW_H
2+
#define MAINWINDOW_H
3+
4+
#include <QMainWindow>
5+
6+
namespace Ui {
7+
class MainWindow;
8+
}
9+
10+
class MainWindow : public QMainWindow
11+
{
12+
Q_OBJECT
13+
14+
public:
15+
explicit MainWindow(QWidget *parent = nullptr);
16+
~MainWindow();
17+
18+
private:
19+
Ui::MainWindow *ui;
20+
};
21+
22+
#endif // MAINWINDOW_H

PyQT5/Chapter_1/mainwindow.ui

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>MainWindow</class>
4+
<widget class="QMainWindow" name="MainWindow">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>400</width>
10+
<height>300</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>MainWindow</string>
15+
</property>
16+
<widget class="QWidget" name="centralWidget">
17+
<widget class="QPushButton" name="TestButton">
18+
<property name="geometry">
19+
<rect>
20+
<x>10</x>
21+
<y>10</y>
22+
<width>113</width>
23+
<height>32</height>
24+
</rect>
25+
</property>
26+
<property name="text">
27+
<string>Test Button</string>
28+
</property>
29+
</widget>
30+
</widget>
31+
<widget class="QMenuBar" name="menuBar">
32+
<property name="enabled">
33+
<bool>true</bool>
34+
</property>
35+
<property name="geometry">
36+
<rect>
37+
<x>0</x>
38+
<y>0</y>
39+
<width>400</width>
40+
<height>22</height>
41+
</rect>
42+
</property>
43+
</widget>
44+
<widget class="QToolBar" name="mainToolBar">
45+
<attribute name="toolBarArea">
46+
<enum>TopToolBarArea</enum>
47+
</attribute>
48+
<attribute name="toolBarBreak">
49+
<bool>false</bool>
50+
</attribute>
51+
</widget>
52+
<widget class="QStatusBar" name="statusBar">
53+
<property name="enabled">
54+
<bool>true</bool>
55+
</property>
56+
</widget>
57+
</widget>
58+
<layoutdefault spacing="6" margin="11"/>
59+
<resources/>
60+
<connections/>
61+
</ui>

PyQT5/Chapter_1/mark_tool.pro

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#-------------------------------------------------
2+
#
3+
# Project created by QtCreator 2019-06-04T13:54:36
4+
#
5+
#-------------------------------------------------
6+
7+
QT += core gui
8+
9+
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
10+
11+
TARGET = mark_tool
12+
TEMPLATE = app
13+
14+
# The following define makes your compiler emit warnings if you use
15+
# any feature of Qt which has been marked as deprecated (the exact warnings
16+
# depend on your compiler). Please consult the documentation of the
17+
# deprecated API in order to know how to port your code away from it.
18+
DEFINES += QT_DEPRECATED_WARNINGS
19+
20+
# You can also make your code fail to compile if you use deprecated APIs.
21+
# In order to do so, uncomment the following line.
22+
# You can also select to disable deprecated APIs only up to a certain version of Qt.
23+
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
24+
25+
CONFIG += c++11
26+
27+
SOURCES += \
28+
main.cpp \
29+
mainwindow.cpp
30+
31+
HEADERS += \
32+
mainwindow.h
33+
34+
FORMS += \
35+
mainwindow.ui
36+
37+
# Default rules for deployment.
38+
qnx: target.path = /tmp/$${TARGET}/bin
39+
else: unix:!android: target.path = /opt/$${TARGET}/bin
40+
!isEmpty(target.path): INSTALLS += target

0 commit comments

Comments
 (0)