Skip to content

Instantly share code, notes, and snippets.

@RavenKyu
Created June 3, 2015 08:50
Show Gist options
  • Save RavenKyu/a80f8325280ad412f815 to your computer and use it in GitHub Desktop.
Save RavenKyu/a80f8325280ad412f815 to your computer and use it in GitHub Desktop.
Example: QClipboard
# coding: utf-8
import sys
from PyQt5 import QtWidgets
from PyQt5 import QtGui
from PyQt5.QtCore import pyqtSlot # pyqtSlot 프로퍼티를 사용하기 위함
datas = ['정철아','문서를','보면','다 나온다']
class Form(QtWidgets.QDialog):
def __init__(self, parent=None):
QtWidgets.QDialog.__init__(self, parent)
self.setGeometry(100,100,250,100)
self.cb = QtWidgets.QComboBox(self)
self.cb.addItems(datas)
self.bt_1 = QtWidgets.QPushButton('복사', self)
self.bt_1.clicked.connect(self.slot_copy_clipboard_1)
hbox_1 = QtWidgets.QHBoxLayout()
hbox_1.addWidget(self.cb)
hbox_1.addWidget(self.bt_1)
self.le = QtWidgets.QLineEdit(self)
self.bt_2 = QtWidgets.QPushButton('복사', self)
self.bt_2.clicked.connect(self.slot_copy_clipboard_2)
hbox_2 = QtWidgets.QHBoxLayout()
hbox_2.addWidget(self.le)
hbox_2.addWidget(self.bt_2)
self.te = QtWidgets.QTextEdit(self)
vbox = QtWidgets.QVBoxLayout()
vbox.addLayout(hbox_1)
vbox.addLayout(hbox_2)
vbox.addWidget(self.te)
self.setLayout(vbox)
self.qclip = QtWidgets.QApplication.clipboard()
@pyqtSlot()
def slot_copy_clipboard_1(self):
self.qclip.setText(self.cb.currentText())
@pyqtSlot()
def slot_copy_clipboard_2(self):
self.qclip.setText(self.le.text())
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
w = Form()
w.show()
sys.exit(app.exec())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment