我尝试在PyQt类中添加一个函数,但它总是返回一个错误.
# Error: TypeError: connect() slot argument should be a callable or a signal, not 'NoneType' #
Run Code Online (Sandbox Code Playgroud)
def commander (self, arg):
exec arg
def aButton (self, layout, **kwargs):
name = kwargs.pop("name","Button")
command = kwargs.pop("command", "" )
button = QtGui.QPushButton(name)
button.clicked.connect(self.commander(command))
layout.addWidget(button)
return button
Run Code Online (Sandbox Code Playgroud)
可能是这里有人可以帮我解决:')Thx!
我有一些困难QGraphicsView和QGraphicsScene.当我在场景中缩放/取消缩放并使用mousePressEvent创建项目时,我的位置有一个偏移量.如何避免这种情况?
event.pos() 似乎是问题..
from PyQt4 import QtCore, QtGui
class graphicsItem (QtGui.QGraphicsItem):
def __init__ (self):
super(graphicsItem, self).__init__()
self.rectF = QtCore.QRectF(0,0,10,10)
def boundingRect (self):
return self.rectF
def paint (self, painter=None, style=None, widget=None):
painter.fillRect(self.rectF, QtCore.Qt.red)
class graphicsScene (QtGui.QGraphicsScene):
def __init__ (self, parent=None):
super (graphicsScene, self).__init__ (parent)
class graphicsView (QtGui.QGraphicsView):
def __init__ (self, parent = None):
super (graphicsView, self).__init__ (parent)
self.parent = parent
def mousePressEvent(self, event):
super (graphicsView, self).mousePressEvent(event)
item = graphicsItem()
position = QtCore.QPointF(event.pos()) - item.rectF.center()
item.setPos(position.x() , position.y()) …Run Code Online (Sandbox Code Playgroud) 如何列出包含类的所有功能但不按字母顺序重新排序的列表?因为实际上我有:
[ foo.__dict__.get(a) for a in dir(foo) if isinstance(foo.__dict__.get(a), types.FunctionType) ]
Run Code Online (Sandbox Code Playgroud)
它返回给我一个列表但重新排序...我也尝试过一个装饰者:
def decorator ():
listing = []
def wrapped (func):
listing.append(func)
return func
wrapped.listing = listing
return wrapped
Run Code Online (Sandbox Code Playgroud)
那很好但是,我需要在我班级的每个功能上添加一个装饰器......可能你有一些技巧?