反馈
我正在进行PyQt5安装(基于Qt5.2.1/Sip 4.15.5 API 11 ???)和标准Python3(3.3.2+)解释器兼容PyQt5(> = 3.3.2),因为它不是可以在Ubuntu 12.04上编译Python3.3-5,然后无法安装PyQt5(python 3.3.2或更高版本).
平台:
jeby6372@mercure:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 13.10
Release: 13.10
Codename: saucy
jeby6372@mercure:~$ uname -a
Linux mercure 3.11.0-13-generic #20-Ubuntu SMP Wed Oct 23 07:38:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
Run Code Online (Sandbox Code Playgroud)
在安装过程中一切似乎都运行良好,PyQt5导入有效,但是当我尝试通过python3解释器导入模块时,会出现此错误:
>>> import PyQt5
>>> from PyQt5.QtCore import *
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
RuntimeError: the sip module implements API v10.0 to v10.1 but the PyQt5.QtCore …Run Code Online (Sandbox Code Playgroud) 我想创建一个半透明背景的全屏窗口,但是完全可见的子窗口小部件(覆盖效果的种类).
这是我到目前为止所拥有的:
import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
app = QApplication(sys.argv)
# Create the main window
window = QMainWindow()
window.setWindowOpacity(0.3)
window.setAttribute(Qt.WA_NoSystemBackground, True)
window.setWindowFlags(Qt.FramelessWindowHint)
# Create the button
pushButton = QPushButton(window)
pushButton.setGeometry(QRect(240, 190, 90, 31))
pushButton.setText("Finished")
pushButton.clicked.connect(app.quit)
# Center the button
qr = pushButton.frameGeometry()
cp = QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
pushButton.move(qr.topLeft())
# Run the application
window.showFullScreen()
sys.exit(app.exec_())
Run Code Online (Sandbox Code Playgroud)
这会产生半透明效果,但即使按钮也是半透明的.
我也试过替换了
window.setWindowOpacity(0.3)
Run Code Online (Sandbox Code Playgroud)
通过这个电话
window.setAttribute(Qt.WA_TranslucentBackground, True)
Run Code Online (Sandbox Code Playgroud)
但无济于事,在这种情况下,背景是完全透明的(按钮正确完全可见).
解决方案:(感谢Aaron的建议):
诀窍在于为主窗口实现自定义paintEvent.
import sys
from PyQt5.QtCore import * …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 PyQt5 中的基本语法突出显示、代码完成和可点击的函数和变量来制作一个简单的文本编辑器。我最大的希望是使用 PyQt5 的 QScintilla 端口
。
我在 Eli Bendersky 网站 ( http://eli.thegreenplace.net/2011/04/01/sample-using-qscintilla-with-pyqt )上找到了以下基于 QScintilla 的文本编辑器示例,Victor S. 已将其改编为 PyQt5 )。我认为这个例子是一个很好的起点:
#-------------------------------------------------------------------------
# qsci_simple_pythoneditor.pyw
#
# QScintilla sample with PyQt
#
# Eli Bendersky (eliben@gmail.com)
# This code is in the public domain
#-------------------------------------------------------------------------
import sys
import sip
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.Qsci import QsciScintilla, QsciLexerPython
class SimplePythonEditor(QsciScintilla):
ARROW_MARKER_NUM = 8
def __init__(self, parent=None):
super(SimplePythonEditor, self).__init__(parent)
# Set the default …Run Code Online (Sandbox Code Playgroud) 我需要获取动态内容,该内容由 ajax js 调用加载。
我真的不知道如何使用 PyQt,但我希望我能做到这一点。HTML是这样的:
<a href="#" id="id" onclick="A4J.AJAX.Submit('j_id0:j_id1:j_id110',event,{'similarityGroupingId':'j_id0:j_id1:j_id110:j_id582:0:j_id584'});return false;">NETHERLANDS</a>`
Run Code Online (Sandbox Code Playgroud)
我可以使用以下简单代码使用 PyQt 呈现页面:
def render(source_html):
import sys
from PyQt5.QtCore import QEventLoop
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWebEngineWidgets import QWebEngineView
class Render(QWebEngineView):
def __init__(self, html):
self.html = None
self.app = QApplication(sys.argv)
QWebEngineView.__init__(self)
self.loadFinished.connect(self._loadFinished)
self.setHtml(html)
while self.html is None:
self.app.processEvents(QEventLoop.ExcludeUserInputEvents | QEventLoop.ExcludeSocketNotifiers | QEventLoop.WaitForMoreEvents)
self.app.quit()
def _callable(self, data):
self.html = data
def _loadFinished(self, result):
self.page().toHtml(self._callable)
return Render(source_html).html
import requests
sample_html = requests.get('https://riverbankcomputing.com/software/pyqt/').text
print(render(sample_html))
Run Code Online (Sandbox Code Playgroud)
我如何运行“onclick”并获取内容?
我正在尝试使用Pyinstaller捆绑PyQt项目.我尝试使用命令创建包pyinstaller --onedir Hello.py.
这会创建dist文件夹并具有Hello.exe.在运行时它会收到错误:此应用程序无法启动,因为它无法在""中找到或加载Qt平台插件"windows".重新安装应用程序可能会解决此问题.
我在PC上解决了这个问题
或者
dist\Hello\PyQt5\Qt\plugins\platform文件夹复制到Hello.exe所在的位置.但是当我使用命令--onefile捆绑到单个文件并且在未设置QT_QPA_PLATFORM_PLUGIN_PATH的任何其他计算机上运行时,会出现此问题.
有人可以帮助找出问题所在.
我在相同的conda虚拟环境中有PyQt5和OpenCV.
opencv-python==3.4.1.15
PyQt5==5.10.1
Run Code Online (Sandbox Code Playgroud)
每当我运行我的PyQt5应用程序时,我会收到许多警告:
objc[7992]: Class QCocoaPageLayoutDelegate is implemented in both /Users/alexryan/miniconda3/envs/qacker/lib/python3.5/site-packages/cv2/.dylibs/QtGui (0x109ae0290) and /Users/alexryan/miniconda3/envs/qacker/lib/python3.5/site-packages/PyQt5/Qt/lib/QtPrintSupport.framework/Versions/5/QtPrintSupport (0x10a387f20). One of the two will be used. Which one is undefined.
objc[7992]: Class QCocoaPrintPanelDelegate is implemented in both /Users/alexryan/miniconda3/envs/qacker/lib/python3.5/site-packages/cv2/.dylibs/QtGui (0x109ae0308) and /Users/alexryan/miniconda3/envs/qacker/lib/python3.5/site-packages/PyQt5/Qt/lib/QtPrintSupport.framework/Versions/5/QtPrintSupport (0x10a387f70). One of the two will be used. Which one is undefined.
objc[7992]: Class QCocoaApplicationDelegate is implemented in both /Users/alexryan/miniconda3/envs/qacker/lib/python3.5/site-packages/cv2/.dylibs/QtGui (0x109ae0010) and /Users/alexryan/miniconda3/envs/qacker/lib/python3.5/site-packages/PyQt5/Qt/plugins/platforms/libqcocoa.dylib (0x10c6ed480). One of the two will be used. Which one is undefined.
objc[7992]: Class QNSApplication is implemented in both …Run Code Online (Sandbox Code Playgroud) 我刚刚在我的 Windows 系统上安装了带有 Python 3.6 的 Anaconda 5.2。还通过具有管理员权限的 pip 安装了 pyqt5 和 pyqt5-tools。现在,当我运行 pyuic5.exe 来转换 ui 文件时,它显示以下错误:
Traceback (most recent call last):
File "C:\Users\AshfaqurRahman\Anaconda3\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Users\AshfaqurRahman\Anaconda3\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\AshfaqurRahman\AppData\Roaming\Python\Python36\site-packages\PyQt5\uic\pyuic.py", line 26, in <module>
from PyQt5 import QtCore
ModuleNotFoundError: No module named 'PyQt5.sip'
Run Code Online (Sandbox Code Playgroud)
我尝试使用 pip 安装 PyQt5-sip 包。但是它已经安装在我的系统中。
为什么会出现这个问题?我怎么解决这个问题?
我正在研究 PyQt5 GUI,到目前为止,我只是有使用 python 脚本的经验,并没有深入研究创建用户界面。
GUI 必须用于不同的屏幕(可能还有一些旧的 4:3 比例屏幕),并且需要在不同尺寸下看起来不错。现在,我让我的生活更轻松的方法是强制执行窗口的固定纵横比并根据窗口大小调整不同元素的大小。
from PyQt5 import QtCore, QtGui, QtWidgets
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, parent= None):
super().__init__(parent)
self.form_widget = FormWidget(self)
self.setCentralWidget(self.form_widget)
self.resize(200, 400)
self.sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
self.sizePolicy.setHeightForWidth(True)
self.setSizePolicy(self.sizePolicy)
def heightForWidth(self, width):
return width * 2
class FormWidget(QtWidgets.QWidget):
def __init__(self, parent):
super().__init__(parent)
def resizeEvent(self, event):
f = self.font()
temp = event.size().height()
f.setPixelSize(temp / 16)
self.setFont(f)
return super().resizeEvent(event)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
w = MainWindow()
w.show()
sys.exit(app.exec_())
Run Code Online (Sandbox Code Playgroud)
根据窗口大小调整元素大小工作正常,但根本不保留窗口纵横比。我heightForWidth从旧的 PyQt4 …
升级到 python-pyqt5 5.12-2 后,当我尝试从 QtWidgets 导入时出现此错误
from PyQt5.QtWidgets import *
Run Code Online (Sandbox Code Playgroud)
错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'PyQt5.sip'
Run Code Online (Sandbox Code Playgroud)
关于如何解决这个问题的任何想法?
我尝试使用安装 PyQt5
pip install PyQt5
Run Code Online (Sandbox Code Playgroud)
和
sudo -H pip install PyQt5
Run Code Online (Sandbox Code Playgroud)
他们都给了我错误
ERROR: Could not find a version that satisfies the requirement PyQt5 (from versions: none)
ERROR: No matching distribution found for PyQt5
Run Code Online (Sandbox Code Playgroud)
我使用 Ubuntu 18.04。
我的python版本是:Python 2.7.15rc1
我已经安装了 python3-pip 并尝试使用安装 PyQt5
pip3 install PyQt5
Run Code Online (Sandbox Code Playgroud)
我收到错误
Traceback (most recent call last):
File "/usr/local/bin/pip3", line 5, in <module>
from pkg_resources import load_entry_point
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 3241, in <module>
@_call_aside
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 3225, in _call_aside
f(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 3254, …Run Code Online (Sandbox Code Playgroud) pyqt5 ×10
python ×8
pyqt ×6
python-3.x ×3
qt ×2
anaconda ×1
aspect-ratio ×1
conda ×1
html ×1
import ×1
javascript ×1
opencv ×1
pip ×1
pyinstaller ×1
qscintilla ×1
qt5 ×1
ubuntu ×1