pyqt项目18-QSpinBox(微调框2-高精度)

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

pyqt项目18-QSpinBox(微调框2-高精度)

  • 前言
  • 一、所学内容
  • 二、完整代码
  • 总结


前言

提示:这里可以添加本文要记录的大概内容:


提示:以下是本篇文章正文内容,下面案例可供参考

一、所学内容

1. QDoubleSpinBox
1.1 self.doubleSpinBox.setDecimals(value)

二、完整代码

2.1 界面逻辑

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'untitled.ui'
#
# Created by: PyQt5 UI code generator 5.13.1
#
# WARNING! All changes made in this file will be lost!


from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(800, 600)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.doubleSpinBox = QtWidgets.QDoubleSpinBox(self.centralwidget)
        self.doubleSpinBox.setGeometry(QtCore.QRect(80, 80, 191, 23))
        self.doubleSpinBox.setObjectName("doubleSpinBox")
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(80, 150, 201, 16))
        self.label.setObjectName("label")
        self.horizontalSlider = QtWidgets.QSlider(self.centralwidget)
        self.horizontalSlider.setGeometry(QtCore.QRect(80, 200, 181, 16))
        self.horizontalSlider.setMinimum(2)
        self.horizontalSlider.setMaximum(10)
        self.horizontalSlider.setOrientation(QtCore.Qt.Horizontal)
        self.horizontalSlider.setTickPosition(QtWidgets.QSlider.TicksAbove)
        self.horizontalSlider.setObjectName("horizontalSlider")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 19))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        self.horizontalSlider.valueChanged['int'].connect(MainWindow.change_value)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.label.setText(_translate("MainWindow", "double spin box精度设置:"))

2.2 业务逻辑

import random
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox
from untitled import Ui_MainWindow
from PyQt5.QtCore import Qt, QBasicTimer


# ======haozh-検索画面(这里继承的类就是Qtdesigner生成出来的.py文件)=====
class My_Form(QMainWindow, Ui_MainWindow):
    def __init__(self):
        super(My_Form, self).__init__()
        self.setupUi(self)

        show_message = "double spin box精度设置:" + str(self.horizontalSlider.value())
        self.label.setText(show_message)

    def change_value(self, value):
        self.label.setText("double spin box精度设置:" + str(value))
        self.doubleSpinBox.setDecimals(value)



# ======haozh-主程序调用=====
if __name__=='__main__':
    app=QApplication(sys.argv)
    index=My_Form()
    index.show()
    sys.exit(app.exec_())


总结

提示:这里对文章进行总结:
例如:以上就是今天要讲的内容,本文仅仅简单介绍了pandas的使用,而pandas提供了大量能使我们快速便捷地处理数据的函数和方法。

你可能感兴趣的:(pyqt5,pyqt,qt,开发语言)