我制作了一个文本框,想要从文本框中复制所有内容,然后通过按钮粘贴。
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName(_fromUtf8("Form"))
Form.resize(943, 655)
self.textEdit = Qsci.QsciScintilla(Form)
self.textEdit.setGeometry(QtCore.QRect(10, 10, 861, 461))
self.textEdit.setToolTip(_fromUtf8(""))
self.textEdit.setWhatsThis(_fromUtf8(""))
self.textEdit.setStyleSheet(_fromUtf8(""))
self.textEdit.setFrameShape(QtGui.QFrame.StyledPanel)
self.textEdit.setFrameShadow(QtGui.QFrame.Plain)
self.textEdit.setObjectName(_fromUtf8("textEdit"))
self.pushButton = QtGui.QPushButton(Form)
self.pushButton.setGeometry(QtCore.QRect(530, 570, 93, 28))
self.pushButton.setObjectName(_fromUtf8("pushButton"))
self.retranslateUi(Form)
QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL(_fromUtf8("clicked()")), self.textEdit.selectAll)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
Form.setWindowTitle(_translate("Form", "Form", None))
self.pushButton.setText(_translate("Form", "run", None))
from PyQt4 import Qsci
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
Form = QtGui.QWidget()
ui = Ui_Form()
ui.setupUi(Form)
Form.show()
sys.exit(app.exec_())
我基本上想让按钮通过按钮到打印机来打印文本框的内容。
like so
self.pushButton.setText(_translate("Form", "run", None))
self.pushButton.clicked.connect(self.Paste)
def Paste(self):
print "content"
我尝试了很多,但没有一种像。
def Paste(self):
x = QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL(_fromUtf8("clicked()")), self.textEdit.selectAll)
print x
答案 0 :(得分:0)
为什么回拨中的重复连接信号会形成信号?
无论如何,QsciScintilla
中的文本框,我阅读的文档正在使用QString QsciScintilla::text ( ) const。要输出到控制台,您只需调用此方法;
def Paste (self):
print self.textEdit.text()