Skip to content

Commit f17ae96

Browse files
committed
修改 PyQT5代碼
1 parent e66da66 commit f17ae96

File tree

10 files changed

+106
-151
lines changed

10 files changed

+106
-151
lines changed
Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,32 @@
1-
#-------------------------------------------------
2-
#
3-
# Project created by QtCreator 2019-06-04T13:54:36
4-
#
5-
#-------------------------------------------------
6-
71
QT += core gui
82

93
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
104

11-
TARGET = mark_tool
12-
TEMPLATE = app
5+
CONFIG += c++11
136

147
# 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
8+
# any Qt feature that has been marked deprecated (the exact warnings
169
# depend on your compiler). Please consult the documentation of the
1710
# deprecated API in order to know how to port your code away from it.
1811
DEFINES += QT_DEPRECATED_WARNINGS
1912

20-
# You can also make your code fail to compile if you use deprecated APIs.
13+
# You can also make your code fail to compile if it uses deprecated APIs.
2114
# In order to do so, uncomment the following line.
2215
# You can also select to disable deprecated APIs only up to a certain version of Qt.
2316
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
2417

25-
CONFIG += c++11
26-
2718
SOURCES += \
28-
main.cpp \
29-
mainwindow.cpp
19+
main.cpp \
20+
mainwindow.cpp
3021

3122
HEADERS += \
32-
mainwindow.h
23+
mainwindow.h
3324

3425
FORMS += \
35-
mainwindow.ui
26+
mainwindow.ui
27+
28+
TRANSLATIONS += \
29+
MarkQt5_zh_TW.ts
3630

3731
# Default rules for deployment.
3832
qnx: target.path = /tmp/$${TARGET}/bin
Lines changed: 30 additions & 48 deletions
Large diffs are not rendered by default.

PyQT5/Chapter_1/MarkQt5_zh_TW.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!DOCTYPE TS>
3+
<TS version="2.1" language="MarkQt5_zh_TW"></TS>

PyQT5/Chapter_1/MarkQtUI.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# Form implementation generated from reading ui file 'mainwindow.ui'
4+
#
5+
# Created by: PyQt5 UI code generator 5.14.1
6+
#
7+
# WARNING! All changes made in this file will be lost!
8+
9+
10+
from PyQt5 import QtCore, QtGui, QtWidgets
11+
12+
13+
class Ui_MainWindow(object):
14+
def setupUi(self, MainWindow):
15+
MainWindow.setObjectName("MainWindow")
16+
MainWindow.resize(800, 600)
17+
self.centralwidget = QtWidgets.QWidget(MainWindow)
18+
self.centralwidget.setObjectName("centralwidget")
19+
self.Test_Button = QtWidgets.QPushButton(self.centralwidget) # 我們剛剛定義的Object Name
20+
self.Test_Button.setGeometry(QtCore.QRect(20, 0, 113, 32))
21+
self.Test_Button.setObjectName("Test_Button")
22+
MainWindow.setCentralWidget(self.centralwidget)
23+
self.menubar = QtWidgets.QMenuBar(MainWindow)
24+
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 22))
25+
self.menubar.setObjectName("menubar")
26+
MainWindow.setMenuBar(self.menubar)
27+
self.statusbar = QtWidgets.QStatusBar(MainWindow)
28+
self.statusbar.setObjectName("statusbar")
29+
MainWindow.setStatusBar(self.statusbar)
30+
31+
self.retranslateUi(MainWindow)
32+
QtCore.QMetaObject.connectSlotsByName(MainWindow)
33+
34+
def retranslateUi(self, MainWindow):
35+
_translate = QtCore.QCoreApplication.translate
36+
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
37+
self.Test_Button.setText(_translate("MainWindow", "嗨起來")) # 這是我們剛剛改的名稱,你想從這裡改也是可以的喔!

PyQT5/Chapter_1/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#include "mainwindow.h"
2+
23
#include <QApplication>
34

45
int main(int argc, char *argv[])
56
{
67
QApplication a(argc, argv);
78
MainWindow w;
89
w.show();
9-
1010
return a.exec();
1111
}

PyQT5/Chapter_1/main.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
# -*- coding: utf-8 -*-
22

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-
93
import sys
104
import os
115
import time
@@ -16,7 +10,7 @@
1610
from PyQt5.QtGui import QStandardItemModel, QStandardItem
1711
from PyQt5.QtCore import pyqtSlot
1812

19-
from mark_tool import Ui_MainWindow
13+
from MarkQtUI import Ui_MainWindow
2014

2115
class Mark(QMainWindow, Ui_MainWindow):
2216

@@ -27,13 +21,15 @@ def __init__(self, parent=None):
2721
# 建立ui介面
2822
self.setupUi(self)
2923
# 這功能主要是點擊了這個按鈕要執行什麼?
30-
# self.TestButton 這個 function 在 mark_tool.Ui_MainWindow內
31-
# 因為已經繼承了Ui_MainWindow,因此執行執行 self.TestButton
24+
# self.Test_Button 這個 function 在 MarkQtUI.Ui_MainWindow內
25+
# 因為已經繼承了Ui_MainWindow,因此執行 self.Test_Button
3226
# 點擊了時候會套用下方的function test_button_clicked,會將值輸出
33-
# 如果沒有這行,點擊按鈕不會有任何的東做
34-
self.TestButton.clicked.connect(self.test_button_clicked)
27+
# 如果沒有這行,點擊按鈕不會有任何的動作
28+
self.Test_Button.clicked.connect(self.test_button_clicked)
29+
3530

3631
def test_button_clicked(self):
32+
# 你看要他輸出什麼事情,這裡則是會在終端機印出 test
3733
print('test')
3834

3935
if __name__ == "__main__":

PyQT5/Chapter_1/mainwindow.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#include "mainwindow.h"
22
#include "ui_mainwindow.h"
33

4-
MainWindow::MainWindow(QWidget *parent) :
5-
QMainWindow(parent),
6-
ui(new Ui::MainWindow)
4+
MainWindow::MainWindow(QWidget *parent)
5+
: QMainWindow(parent)
6+
, ui(new Ui::MainWindow)
77
{
88
ui->setupUi(this);
99
}
@@ -12,3 +12,4 @@ MainWindow::~MainWindow()
1212
{
1313
delete ui;
1414
}
15+

PyQT5/Chapter_1/mainwindow.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,19 @@
33

44
#include <QMainWindow>
55

6-
namespace Ui {
7-
class MainWindow;
8-
}
6+
QT_BEGIN_NAMESPACE
7+
namespace Ui { class MainWindow; }
8+
QT_END_NAMESPACE
99

1010
class MainWindow : public QMainWindow
1111
{
1212
Q_OBJECT
1313

1414
public:
15-
explicit MainWindow(QWidget *parent = nullptr);
15+
MainWindow(QWidget *parent = nullptr);
1616
~MainWindow();
1717

1818
private:
1919
Ui::MainWindow *ui;
2020
};
21-
2221
#endif // MAINWINDOW_H

PyQT5/Chapter_1/mainwindow.ui

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,56 +6,40 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>400</width>
10-
<height>300</height>
9+
<width>800</width>
10+
<height>600</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
1414
<string>MainWindow</string>
1515
</property>
16-
<widget class="QWidget" name="centralWidget">
17-
<widget class="QPushButton" name="TestButton">
16+
<widget class="QWidget" name="centralwidget">
17+
<widget class="QPushButton" name="Test_Button">
1818
<property name="geometry">
1919
<rect>
20-
<x>10</x>
21-
<y>10</y>
20+
<x>20</x>
21+
<y>0</y>
2222
<width>113</width>
2323
<height>32</height>
2424
</rect>
2525
</property>
2626
<property name="text">
27-
<string>Test Button</string>
27+
<string>嗨起來</string>
2828
</property>
2929
</widget>
3030
</widget>
31-
<widget class="QMenuBar" name="menuBar">
32-
<property name="enabled">
33-
<bool>true</bool>
34-
</property>
31+
<widget class="QMenuBar" name="menubar">
3532
<property name="geometry">
3633
<rect>
3734
<x>0</x>
3835
<y>0</y>
39-
<width>400</width>
36+
<width>800</width>
4037
<height>22</height>
4138
</rect>
4239
</property>
4340
</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>
41+
<widget class="QStatusBar" name="statusbar"/>
5742
</widget>
58-
<layoutdefault spacing="6" margin="11"/>
5943
<resources/>
6044
<connections/>
6145
</ui>

PyQT5/Chapter_1/mark_tool.py

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)