小编iMa*_*ath的帖子

在 Windows 上 setRange(0, 0) 时将文本放在 QProgressBar 的中间?

在 Windows 上使用 setRange(0, 0) 时,如何在 QProgressBar 中间放置文本(不仅仅是数字)?

下面是一个 PyQt 示例,它仍然无法按预期工作。

import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *

class MainWindow(QMainWindow):

    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.resize(800, 600)

#        self.lb=QLabel('finding resource   ')

        self.pb = QProgressBar()
        self.pb.setRange(0, 0)

        self.pb.setAlignment(Qt.AlignCenter)
        self.pb.setFormat('finding resource...')
        self.pb.setStyleSheet("text-align: center;")

#        self.pb.setTextVisible(False)


        self.statusBar().setSizeGripEnabled(False)
#        print(self.statusBar().layout() )
        self.statusBar().setStyleSheet("QStatusBar::item {border: none;}")
        self.statusBar().addPermanentWidget(self.pb, 1)


if __name__ == "__main__":
    app = QApplication(sys.argv)

    ui = MainWindow()
    ui.show()
    sys.exit(app.exec_())
Run Code Online (Sandbox Code Playgroud)

qt pyqt qprogressbar pyside

3
推荐指数
1
解决办法
5105
查看次数

以LCD格式显示系统时钟时间

我只想以LCD格式显示系统时钟时间.我也希望用hh:mm:ss格式显示时间.我的代码如下.但是当我运行它时,它并不像我预期的那样.有谁能解释为什么?

import sys
from PySide import QtGui, QtCore

class Example(QtGui.QWidget):

    def __init__(self):
        super(Example, self).__init__()
        self.initUI()
        timer = QtCore.QTimer(self)
        timer.timeout.connect(self.showlcd)
        timer.start(1000)
        self.showlcd()

    def initUI(self):

        self.lcd = QtGui.QLCDNumber(self)
        self.setGeometry(30, 30, 800, 600)
        self.setWindowTitle('Time')

        vbox = QtGui.QVBoxLayout()
        vbox.addWidget(self.lcd)
        self.setLayout(vbox)

        self.show()

    def showlcd(self):
        time = QtCore.QTime.currentTime()
        text = time.toString('hh:mm:ss')
        self.lcd.display(text)


def main():

    app = QtGui.QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())


if __name__ == '__main__':
    main()
Run Code Online (Sandbox Code Playgroud)

python pyqt4

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

如何使 QAbstractTableModel 的数据可检查

如何使 QAbstractTableModel 的数据可检查

我想让用户可以选中或取消选中以下代码中的每个单元格,如何修改代码?

根据 Qt 文档?Qt::CheckStateRole 并设置 Qt::ItemIsUserCheckable 可能会被使用,所以任何人都可以给出一个小样本?

import sys                                 
from PyQt4.QtGui import *                              
from PyQt4.QtCore import *

class MyModel(QAbstractTableModel):   

    def __init__(self, parent=None):   

        super(MyModel, self).__init__(parent)   

    def rowCount(self, parent = QModelIndex()):   

        return 2

    def columnCount(self,parent = QModelIndex()) :   

        return 3

    def data(self,index, role = Qt.DisplayRole) :   

        if (role == Qt.DisplayRole):   

            return "Row{}, Column{}".format(index.row() + 1, index.column() +1)   

        return None

if __name__ == '__main__':   

    app =QApplication(sys.argv)   

    tableView=QTableView()   
    myModel = MyModel (None);    
    tableView.setModel( myModel );          
    tableView.show();   
    sys.exit(app.exec_())
Run Code Online (Sandbox Code Playgroud)

qt pyqt pyside

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

Sublime - 将#放在行的开头而不是注释时代码的开头

通过super+ 将注释插入Python时/,它会将#代码放在代码的开头,如下所示:

在此输入图像描述

我想把它放在#一行的开头,像这样:

在此输入图像描述

是否有任何设置允许我这样做?

python sublimetext sublimetext2 sublimetext3

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

在 PyQt 应用程序中嵌入 aiohttp 服务器

我打算在 PyQt 应用程序中嵌入 aiohttp 服务器,但是当我运行下面的代码时,Qt 窗口无法显示,我知道这是由 引起的web.run_app(app),我尝试将其移动到线程中,但是然后我明白了RuntimeError: There is no current event loop in thread \'Dummy-1\',那我该怎么办?我发现asyncqt可能会有所帮助,但我不知道如何使用它来处理 aiohttp 服务器。

\n\n
from PyQt5.QtCore import *\nfrom PyQt5.QtGui import *\nfrom PyQt5.QtWidgets import *\nfrom aiohttp import web\n\n\nclass ThreadGo(QThread):  # threading.Thread\n    # implementing new slots in a QThread subclass is error-prone and discouraged.\n\n    def __init__(self, parent, func, *args, **kwargs):\n        super().__init__(parent)\n        self.func = func\n        self.args = args\n        self.kwargs = kwargs\n        self.result = 0\n\n        onFinished = self.kwargs.get(\'onFinished\')\n        self.finished.connect(onFinished) if onFinished else None …
Run Code Online (Sandbox Code Playgroud)

python pyqt pyqt5 python-asyncio aiohttp

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