标签: pyqt

PyQt:以编程方式选择 QTreeView 中的行并发出信号

我想以编程方式在 QTreeView 中选择一行,我在这里找到了 95% 的答案。

select()方法完美地完成了这项工作,只是它似乎没有触发任何单击视图的事件。

我通过自己调用所需的信号找到了一种解决方法 - 但是是否有任何提示可以模拟人类点击并发送所有相关信号的方法?

这是我的解决方法(Python):

oldIndex=treeView.selectionModel().currentIndex()
newIndex=treeView.model().indexFromItem(item)
#indexes stored----------------------------------
treeView.selectionModel().select(
    newIndex,
    QtGui.QItemSelectionModel.ClearAndSelect)
#selection changed-------------------------------
treeView.selectionModel().currentRowChanged.emit(
    newIndex,
    oldIndex)
#signal manually emitted-------------------------
Run Code Online (Sandbox Code Playgroud)

python qt pyqt selection qtreeview

0
推荐指数
1
解决办法
5122
查看次数

启用和禁用按钮

我正在用 Python 开发一个应用程序,我希望将一组特定的按钮设置为禁用,直到首先单击另一个按钮。例如,当我按下 Sim 卡按钮时,我希望将 Sim Report 按钮设置为启用。

我尝试使用此解决方案来实现该功能:How to make Push Button立即禁用?但它只会禁用按钮 5 秒钟。我只想在相应按钮满足条件时启用特定按钮。我不想生成报告,除非数据已经基本上被解析。

# import Statements
from PyQt5 import QtCore, QtGui, QtWidgets
# from PyQt5.QtWidgets import QMessageBox, QWidget
from reportViewerWindow import Ui_reportViewerWindow
import os

# Main Class that holds User Interface Objects
class Ui_MainWindow(object):

    # Function for Opening Report Viewer Window From Main Window by clicking View Reports button
    def openReportViewer(self):
        self.window = QtWidgets.QMainWindow()
        self.ui = Ui_reportViewerWindow()
        self.ui.setupUi(self.window)
        self.window.show()



    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.setFixedSize(834, 428)
        sizePolicy …
Run Code Online (Sandbox Code Playgroud)

python qt pyqt qpushbutton

0
推荐指数
1
解决办法
1万
查看次数

如何自定义pyqt消息框?

pyqt4

msgBox = QtGui.QMessageBox()
msgBox.setText('Which type of answers would you like to view?')
msgBox.addButton(QtGui.QPushButton('Correct'), QtGui.QMessageBox.YesRole)
msgBox.addButton(QtGui.QPushButton('Incorrect'), QtGui.QMessageBox.NoRole)
msgBox.addButton(QtGui.QPushButton('Cancel'), QtGui.QMessageBox.RejectRole)

if msgBox == QtGui.QMessageBox.YesRole:
     Type = 1
      Doc()
elif msgBox == QtGui.QMessageBox.NoRole:
     Type = 0
     Bank()
else:
    ret = msgBox.exec_()
Run Code Online (Sandbox Code Playgroud)

这会显示一个消息框,但是当单击某个选项时,不会发生任何事情并且该框会关闭。如何让下一个函数运行?

python pyqt pyqt4

0
推荐指数
1
解决办法
3845
查看次数

PyQt5 QPropertyAnimation finished() how to connect

In essence, i'm trying to close a window after the animation completes. In all the documentation and examples i've looked at, they are either in:

  • C++
  • vague "method definitions"
  • Old style slots and connectors

how do i access the finished() that gets 'supposedly' called when the animation finishes?

self.anim = QtCore.QPropertyAnimation(window, b"windowOpacity"
self.anim.setStartValue(1)
self.anim.setEndValue(0)
self.anim.setDuration(3000)
#self.anim.finished.connect() does not exist
#QtCore.QObject.connect(stuff) is deprecated
#self.anim.finished(window.destroy) destroys window immediately
Run Code Online (Sandbox Code Playgroud)

in all the examples i am reading, they use the first commented out method, …

python qt pyqt pyqt5

0
推荐指数
1
解决办法
2783
查看次数

QSystemTrayIcon 不显示

使用 Kubuntu 18.04 (qt5 5.9.5)、Python 3.6。我无法让此代码显示托盘图标;显示了其他图标,例如 Dropbox 等,但不是:

import sys

from PyQt5.QtWidgets import QApplication, QMenu, QSystemTrayIcon, qApp, QMessageBox
from PyQt5.QtGui import QIcon


def run_something():
    print("Running something...")


if __name__ == '__main__':

    print("Creating application...")
    app = QApplication(sys.argv)

    print("Creating menu...")
    menu = QMenu()
    checkAction = menu.addAction("Check Now")
    checkAction.triggered.connect(run_something)
    quitAction = menu.addAction("Quit")
    quitAction.triggered.connect(qApp.quit)

    print("Creating icon...")
    icon = QIcon.fromTheme("system-help")

    print("Creating tray...")
    trayIcon = QSystemTrayIcon(icon, app)
    trayIcon.setContextMenu(menu)

    print("Showing tray...")
    trayIcon.show()
    trayIcon.setToolTip("unko!")
    trayIcon.showMessage("hoge", "moge")

    print("Running application...")
    sys.exit(app.exec_())
Run Code Online (Sandbox Code Playgroud)

显示了消息(“hoge”,“moge”),但我在任何地方都找不到该图标......正如其他帖子所说,在左上角都找不到。

python ubuntu pyqt python-3.x qsystemtrayicon

0
推荐指数
1
解决办法
2749
查看次数

如何使用 Python 选择并缩放 QGIS 中的图层

我正在使用 QGIS 2.8.1,我想选择名为“tempshpfile”的形状文件并缩放到该多边形形状文件上的图层。

我的代码是:

import ogr,os
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from qgis.core import *
import qgis.utils
import glob
import processing
from processing.core.Processing import Processing
from PyQt4.QtCore import QTimer

Processing.initialize()
Processing.updateAlgsList()

# Add array of address below

allFiles = ["C:/Shapefiles/Map_0077421.shp"]
filesLen = len(allFiles)

TexLayer = "C:/Texas_NAD27/Texas_NAD27.shp"

for lop in range(filesLen):
    wb = QgsVectorLayer(allFiles[lop], 'tempshpfile', 'ogr')
    wbTex = QgsVectorLayer(TexLayer, 'TexasGrid', 'ogr')
    QgsMapLayerRegistry.instance().addMapLayer(wb)
    QgsMapLayerRegistry.instance().addMapLayer(wbTex)
Run Code Online (Sandbox Code Playgroud)

python pyqt pyqt4 qgis

0
推荐指数
1
解决办法
2768
查看次数

如何使用QWebEngineView导入本地JavaScript文件?

我正在尝试构建一个简单的示例,在 PyQt 窗口中显示 HTML(包括 JavaScript 代码)

python
import sys
from PyQt5.QtWidgets import QWidget, QApplication, QVBoxLayout
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import QUrl,QDir
from PyQt5.QtWebEngineWidgets import QWebEngineView

class Example(QWidget):

    def __init__(self):
        super().__init__()
        vbox = QVBoxLayout(self)
        self.webEngineView = QWebEngineView()

        self.webEngineView.setHtml("""
            <!DOCTYPE html>
            <html lang="en">
              <head>
                <meta charset="utf-8">
                <script src="file:///home/path/to/jquery-3.6.0.min.js"></script>
              </head>
              <body>
                <!-- page content -->
                <span id="aaa">toto</span>
                <script>
                    $("#aaa").hide()
                </script>
              </body>
            </html>""")

        vbox.addWidget(self.webEngineView)
        self.setLayout(vbox)
        self.show()

sys.argv.append("--disable-web-security")
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
Run Code Online (Sandbox Code Playgroud)

但显然,位于我的 Python 脚本旁边的 jQuery JavaScript …

python pyqt pyqt5 qtwebengine qwebengineview

0
推荐指数
1
解决办法
967
查看次数

将 PyQT 用于命令提示符 (Python) 程序

我究竟会怎么做呢?任何建议都会有所帮助

python pyqt

-1
推荐指数
1
解决办法
3458
查看次数

python是构建桌面应用程序的好选择吗?

我想知道 python 是否是为小型企业开发桌面应用程序的好选择。是否可以使用 PyQT 甚至 Swing + Jython 构建一些东西?最后如何制作可执行文件?

python pyqt

-1
推荐指数
1
解决办法
1808
查看次数

如何在 pyQt 中创建选中复选框的列表

我有超过 10 个复选框。

我需要按用户创建一个选中的复选框列表,因为每个复选框都有自己的功能,该功能取决于选中的复选框的数量!

python pyqt

-1
推荐指数
1
解决办法
1万
查看次数

PyQt5中的menuBar()

我正在尝试将菜单栏加载到我的gui上,但我的类对象没有self.menuBar()的属性.有人可以帮助我,没有教程似乎提供任何方式.

class EmailBlast(QtWidgets.QWidget):
    def __init__(self):
        super().__init__()
        bar = QtWidgets.menuBar() 
        file_menu = bar.addMenu('File')
        file_edit = bar.addMenu('Edit')        
Run Code Online (Sandbox Code Playgroud)

错误信息:

File "BasicEmail.py", line 84, in email_config
self.ui = EmailBlast()
File "BasicEmail.py", line 96, in __init__
self.menuBar()
AttributeError: 'EmailBlast' object has no attribute 'menuBar'
Run Code Online (Sandbox Code Playgroud)

我在这里想念的是什么

更新项目:

class MainWindow(QtWidgets.QMainWindow):
def __init__(self):
    super().__init__()
    self.email_blast_widget = EmailBlast()
    self.setCentralWidget(self.email_blast_widget)
    bar = self.menuBar()
    file_file = bar.addMenu('File')         
    file_edit = bar.addMenu('Edit') 

class EmailBlast(QtWidgets.QWidget):
def __init__(self):
    super().__init__()
    self.text_box = QtWidgets.QTextEdit(self)
    self.save_button = QtWidgets.QPushButton('Save')
    self.clear_button = QtWidgets.QPushButton('Clear')        
    self.open_button = QtWidgets.QPushButton('Open')        
    self.init_ui()
Run Code Online (Sandbox Code Playgroud)

python menu pyqt pyqt5

-2
推荐指数
1
解决办法
5495
查看次数

TypeError:预期的str,字节或os.PathLike对象,而不是元组

因此,我尝试使用GUI创建一种加密程序。这是代码:

import sys
from PyQt4 import QtGui, QtCore
import os
from Crypto.Hash import SHA256
from Crypto import Random
from Crypto.Cipher import AES

class Window(QtGui.QMainWindow):

    def __init__(self):
        super(Window, self).__init__()
        self.setGeometry(50, 50, 500, 300)
        self.setWindowTitle("Encryptionprogram")
        self.setWindowIcon(QtGui.QIcon('pythonicon.png'))

        self.container = QtGui.QWidget()
        self.setCentralWidget(self.container)
        self.container_lay = QtGui.QVBoxLayout()
        self.container.setLayout(self.container_lay)



        extractAction = QtGui.QAction("Leave", self)
        extractAction.setShortcut("Ctrl+Q")
        extractAction.setStatusTip("Leave the app")
        extractAction.triggered.connect(self.close_application)

        mainMenu = self.menuBar()
        fileMenu = mainMenu.addMenu('&File')
        fileMenu.addAction(extractAction)

        #Inputs
        self.Input = QtGui.QLineEdit("Filname", self)

        self.Input.setFixedWidth(200)
        self.Input.setFixedHeight(25)
        self.Input.move(20, 200)
        self.Input.setSizePolicy(QtGui.QSizePolicy.Fixed,
                                 QtGui.QSizePolicy.Fixed)

        self.Input2 = QtGui.QLineEdit("password", self)

        self.Input2.setFixedWidth(200)
        self.Input2.setFixedHeight(25)
        self.Input2.move(220, 200)
        self.Input2.setSizePolicy(QtGui.QSizePolicy.Fixed,
                                  QtGui.QSizePolicy.Fixed)

        self.home() …
Run Code Online (Sandbox Code Playgroud)

python pyqt python-3.x

-4
推荐指数
1
解决办法
1万
查看次数