In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
In this article Xiaobian for you to introduce in detail "what is the principle of data interaction between pyqt5 and html", the content is detailed, the steps are clear, and the details are handled properly. I hope that this article "what is the principle of data interaction between pyqt5 and html" can help you solve your doubts.
Parsing part of the core code
Shared class
Let's take a look at shared classes first.
Class Myshared (QWidget):
Finish = pyqtSignal (list)
Def _ init__ (self):
Super (). _ _ init__ ()
Def PyQt52WebValue (self):
Return "666"
Def Web2PyQt5Value (self, str):
Info = str.split ()
Fullinfo = "user name: {}, password: {}" .format (info [0], info [1])
QMessageBox.information (self, "passing values from Web pages to PyQt5", fullinfo)
Self.finish.emit (info)
Value = pyqtProperty (str, fget=PyQt52WebValue, fset=Web2PyQt5Value)
We have a new knowledge point in this shared class than before: pyqtProperty.
Use the pyqtProperty () function to define the new PyQt property. It is used in the same way as the standard Python property () function. In fact, the PyQt attribute defined in this way is also represented as the Python attribute.
So the question comes again, what is the Python property () function?
According to Python's help documentation, its full form is as follows:
Class property (fget=None, fset=None, fdel=None, doc=None)
The function is to return one of the properties of Python.
Fget is a function that gets the value of an attribute. Fset is a function that sets the value of an attribute. Fdel is a function that deletes the value of an attribute. Doc creates a docstring for this attribute.
A typical use is to define attributes that can be managed x:
Class C:
Def _ init__ (self):
Self._x = None
Def getx (self):
Return self._x
Def setx (self, value):
Self._x = value
Def delx (self):
Del self._x
X = property (getx, setx, delx, "Ihumm the'x 'property.")
If c is an instance of C, c.x will call getter,c.x = value will call setter and del c.x will call delx.
If given, doc will be the docstring of the property attribute. Otherwise, the property replicates the docstring of the fget, if it exists.
This makes it easy to create read-only properties using property () as a decorator:
Class Parrot:
Def _ init__ (self):
Self._voltage = 100000
[email?protected]
Def voltage (self):
"" get the value of the current voltage ""
Return self._voltage
The @ property decorator converts the voltage () method to a read-only property with the same name.
The property object has getter,setter and deleter methods that can be used as decorators, which create a copy of the property and set the corresponding access function to the decorator function. Examples are as follows:
Class C:
Def _ init__ (self):
Self._x = None
[email?protected]
Def x (self):
"" I am the'x' attribute ""
Return self._x
[email?protected]
Def x (self, value):
Self._x = value
[email?protected]
Def x (self):
Del self._x
This code is exactly equivalent to the first example:
X = property (getx, setx, delx, "Ihumm the'x 'property.")
Be sure to give the other functions the same name as the original property (x in this case).
The returned property object also has properties fget,fset and fdel corresponding to the constructor parameters.
In PyQt5, it works like this:
PyQt5.QtCore.pyqtProperty (type, fget=None, fset=None, freset=None, fdel=None, doc=None, designable=True, scriptable=True, stored=True, user=False, constant=False, final=False, notify=None [, revision=0])
It feels complicated!
Create an attribute that is both a Python property and a PyQt property.
Parameters:
Type-type of the attribute. It is an object or string of type Python.
Fget-optional for getting property values.
Fset-optional for setting property values.
Freset-optional for resetting property values to their default values.
Fdel-optional for deleting attributes.
Doc-docstring of the attribute, optional.
Designable-sets the Qt DESIGNABLE flag, optional.
Scriptable-sets the Qt SCRIPTABLE flag, optional.
Stored-sets the Qt STORED flag, optional.
User-sets the Qt USER flag, optional.
Constant-sets the Qt CONSTANT flag, optional.
Final-sets the Qt FINAL flag, optional.
Notify-Notification signal is not bound, optional.
Revision-Export to a revised version of QML.
Return type: property object.
You can also use pyqtProperty () as a decorator in the same way as the standard Python property () function. The following example shows how to define the int property using getter and setter:
From PyQt5.QtCore import QObject, pyqtProperty
Class Foo (QObject):
Def _ init__ (self):
QObject.__init__ (self)
Self._total = 0
[email?protected] (int)
Def total (self):
Return self._total
[email?protected]
Def total (self, value):
Self._total = value
All right, now let's go back and look at the shared classes we defined ourselves.
Def PyQt52WebValue (self):
Return "666"
Write it down, but we can't use it later.
Def Web2PyQt5Value (self, str):
Info = str.split ()
Fullinfo = "user name: {}, password: {}" .format (info [0], info [1])
QMessageBox.information (self, "passing values from Web pages to PyQt5", fullinfo)
Self.finish.emit (info)
When we get the value from the Web page, we process it, divide it into a user name and password, and send it out through a custom signal.
Value = pyqtProperty (str, fget=PyQt52WebValue, fset=Web2PyQt5Value)
After reading this, the article "what is the principle of data interaction between pyqt5 and html" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it to understand it. If you want to know more about related articles, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.