- PyQt5 - Discussion
- PyQt5 - Useful Resources
- PyQt5 - Quick Guide
- PyQt5 - QPixmap Class
- PyQt5 - QClipboard
- PyQt5 - BrushStyle Constants
- PyQt5 - Drawing API
- PyQt5 - Database Handling
- PyQt5 - Drag & Drop
- PyQt5 - Multiple Document Interface
- PyQt5 - QMessageBox
- PyQt5 - QDialog Class
- PyQt5 - Basic Widgets
- PyQt5 - Layout Management
- PyQt5 - Signals & Slots
- PyQt5 - Using Qt Designer
- PyQt5 - Major Classes
- PyQt5 - Hello World
- PyQt5 - What’s New
- PyQt5 - Introduction
- PyQt5 - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
PyQt5 - QCppboard
The QCppboard class provides access to system-wide cppboard that offers a simple mechanism to copy and paste data between apppcations. Its action is similar to QDrag class and uses similar data types.
QApppcation class has a static method cppboard() which returns reference to cppboard object. Any type of MimeData can be copied to or pasted from the cppboard.
Following are the cppboard class methods that are commonly used −
Sr.No. | Methods & Description |
---|---|
1 |
clear() Clears cppboard contents |
2 |
setImage() Copies QImage into cppboard |
3 |
setMimeData() Sets MIME data into cppboard |
4 |
setPixmap() Copies Pixmap object in cppboard |
5 |
setText() Copies QString in cppboard |
6 |
text() Retrieves text from cppboard |
Signal associated with cppboard object is −
Sr.No. | Method & Description |
---|---|
1 |
dataChanged() Whenever cppboard data changes |
Example
In the following example, two TextEdit objects and two Pushbuttons are added to a top level window.
To begin with the cppboard object is instantiated. Copy() method of textedit object copies the data onto the system cppboard. When the Paste button is cpcked, it fetches the cppboard data and pastes it in other textedit object.
import sys from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5.QtWidgets import * class Example(QWidget): def __init__(self): super(Example, self).__init__() self.initUI() def initUI(self): hbox = QVBoxLayout() self.edit1=QTextEdit() hbox.addWidget(self.edit1) self.btn1=QPushButton("Copy") hbox.addWidget(self.btn1) self.edit2=QTextEdit() self.btn2=QPushButton("Paste") hbox.addWidget(self.edit2) hbox.addWidget(self.btn2) self.btn1.cpcked.connect(self.copytext) self.btn2.cpcked.connect(self.pastetext) self.setLayout(hbox) self.setGeometry(300, 300, 300, 200) self.setWindowTitle( Cppboard ) self.show() def copytext(self): #cppboard.setText(self.edit1.copy()) self.edit1.copy() print (cppboard.text()) msg=QMessageBox() msg.setText(cppboard.text()+" copied on cppboard") msg.exec_() def pastetext(self): self.edit2.setText(cppboard.text()) app = QApppcation(sys.argv) cppboard=app.cppboard() ex = Example() ex.setWindowTitle("cppboard Example") sys.exit(app.exec_())
The above code produces the following output −
Advertisements