使用QtDesigner设计界面
使用PyUIC把设计的界面转换成py文件
编写业务代码和Ui文件结合起来
SetTextStyleMainWindow.py
import sys
from SetTextStyle import Ui_SetTextStyle
from PyQt5.QtWidgets import QMainWindow, QApplication, QCheckBox, QSpinBox
from PyQt5.QtGui import QPen, QPalette, QFont
from PyQt5.QtCore import Qt, pyqtSlot
class SetTextStyleMainWindow(QMainWindow):
def __init__(self, parent=None):
super().__init__(parent)
self.__ui = Ui_SetTextStyle()
self.__ui.setupUi(self)
self.setWindowModality(Qt.ApplicationModal)
self.__ui.radioButtonRed.clicked.connect(self.slotBtnRed)
self.__ui.radioButtonBlue.clicked.connect(self.slotBtnBlue)
self.__ui.radioButtonGreen.clicked.connect(self.slotBtnGreen)
self.__ui.checkBox.stateChanged.connect(self.slotItalicFont)
self.__ui.spinBox.valueChanged.connect(self.slotFontSize)
@pyqtSlot(bool)
def slotBtnRed(self, checked):
strText = self.__ui.textEdit.palette()
strText.setColor(QPalette.Text, Qt.red)
self.__ui.textEdit.setPalette(strText)
@pyqtSlot(bool)
def slotBtnBlue(self, checked):
strText = self.__ui.textEdit.palette()
strText.setColor(QPalette.Text, Qt.blue)
self.__ui.textEdit.setPalette(strText)
@pyqtSlot(bool)
def slotBtnGreen(self, checked):
strText = self.__ui.textEdit.palette()
strText.setColor(QPalette.Text, Qt.green)
self.__ui.textEdit.setPalette(strText)
def slotItalicFont(self, checked):
if checked == 0:
b = False
else:
b = True
self.__ui.textEdit.setFontItalic(b)
@pyqtSlot(int)
def slotFontSize(self, size):
self.__ui.textEdit.setFontPointSize(size)
mainWindow = SetTextStyleMainWindow()
def getMainWindow():
#mainWindow.setWindowModality(Qt.ApplicationModal)
mainWindow.show()
'''
if __name__ == "__main__":
app = QApplication(sys.argv)
mainWindow = SetTextStyleMainWindow()
mainWindow.show()
sys.exit(app.exec_())
'''
Py_Initialize();
if (!Py_IsInitialized()) {
return;
}
PyRun_SimpleString("import sys");
PyRun_SimpleString("sys.argv = ['python.py']");
PyRun_SimpleString("sys.path.append('./')");
_moudel = PyImport_ImportModule("SetTextStyleMainWindow");
if (_moudel == nullptr) {
PyErr_PrintEx(0);
} else {
PyObject * pFunc = NULL;
PyObject* pDict = NULL;
PyObject* pClass = NULL;
PyObject* pIns = NULL;
pDict = PyModule_GetDict(_moudel);
assert(pDict != NULL);
pClass = PyDict_GetItemString(pDict, "getMainWindow");
assert(pClass != NULL);
pIns = PyObject_CallObject(pClass, nullptr);
assert(pIns != NULL);
}
Py_Finalize();
注意:要把
#include "Python.h"
放到Cpp文件的第一行,否则编译就会出错!
要把SetTextStyleMainWindow.py放到可执行目录下
aaa
一、 项目分析用VGA显示全屏的红色,VGA(Video Graphics Array,视频图形阵列)是一种电脑显示标准。开发板采用至芯科技zx-1学习板,VGA视频显示接口是256色,颜色位深为8,RGB332的高三位是红色,中间3位是绿色,最低2位是蓝色,当vga_rgb=111_000_000时,显示全红。1.1 原理分析1.1.1 硬件电路原理VGA的硬件电路原理如图1- 1所示,...
在recycleview中使用xutils加载网络图片,关于xutils 的使用可以在这篇博客去学习,在这里直接将java代码讲解import androidx.annotation.NonNull;import androidx.annotation.RequiresApi;import androidx.appcompat.app.AppCompatActivity;import an...
上一篇我们介绍《构建dubbo分布式平台-maven构建ant-framework核心代码annotation》,今天重点讲解的是ant-framework核心代码Base封装过程。 因为涉及到springmvc、mybatis的集成,为了使项目编码更简洁易用,这边将基础的BASE进行封装,其中包括:BaseBean、BaseDao、BaseService、CRUD的基础封装、分页
“一骑红尘妃子笑,无人知是荔枝来。” 相信很多人和小探一样喜欢吃荔枝,但无奈身处宇宙中心——硅谷,买不到刚从福建果园采摘的最鲜嫩的荔枝,只能感慨自己“没有妃子的命,得了妃...
学生实验报告实验课名称:计算机组成原理实验项目名称:微程序控制实验一、实验名称:微程序控制实验二、实验目的:(1)掌握微程序控制器的组成原理。(2)掌握微程序的编制、写入,观察微程序的运行过程。三、实验要求:通过一个微程序控制程序实验,了解微程序控制的的组成原理、工作原理,同时掌握微程序的编制、写入,观察微程序的翻译机器指令的运行过程。四、实验内容:微程序控制器的基本任务是完成当前指令的翻译和执行,即将当前指令的功能转换成可以控制的硬件逻辑部件工作的微命令序列,完成数据传送和各种处理操
I have two lists of numbers, say [1, 2, 3, 4, 5] and [7, 8, 9, 10, 11], and I would like to form a new list which consists of the products of each member in the first list with each member in the seco...
1 MediaPlayer生命周期2 MediaPlayer常用方法MediaPlayer执行流程:创建MediaPlayerMediaPlayer mediaPlayer = new MediaPlayer();或MediaPlayer mediaPlayer = MediaPlayer.create(this, R.raw.test); // 使用该方法不需要再setDat...
单选 sont表示元素在存入集合时进行了排序,数据遍历的结果是按某个排序规则输出的;而order表示每次遍历的序列都是一样的,元素前后关系每次遍历都是确定的,那么下列哪些集合既是sort,又是order的:答案在文末A. HashSetB. LinkedListC. HashMapD. TreeMap多选 关于二方库的snapshot与release的区别,下列哪些说法是正确的:答案在文末A. snapshol在本地响评时,都会到中央仓库下就最的方库,B. release在本地情浑时,如
AMD ROCm PlatformROCm Core Technologyhttps://github.com/RadeonOpenComputeROCm Docshttps://rocmdocs.amd.com/en/latest/ROCm Documentationhttps://github.com/RadeonOpenCompute/ROCm_DocumentationROCmhttps://github.com/RadeonOpenCompute/ROCm1. AMD ROCm
写在前面这里是使用Kotlin构建MVVM应用程序—第四部分:依赖注入Dagger2在前面的一系列文章中,我们了解了在MVVM架构中是如何提供和处理数据的。//////modelval remote=Retrofit.Builder() .baseUrl(Constants.HOST_API) .addCallAdapterFactory(RxJava2C...
NTPAPI.h#ifndef NTPAPI_H#define NTPAPI_H#include <QObject>#include <QUdpSocket>#include <QDateTime>#include <QMutex>class NTPAPI : public QObject{ Q_OBJECTpublic: ...