I'm still quite a newbie with Python and PyQt5, so I have a really basic question. My idea is to build application to download a URL. Here is a picture of my design:
When I right click on the URL from any website, copy it, and go to my application and press on icon on toolbar named (Add URL), the URL should be pasted immediately inside the QLineEdit
.
Here is my code:
from PyQt5.QtWidgets import*
from PyQt5.QtCore import*
from PyQt5.QtGui import*
from PyQt5.uic import loadUiType
from PyQt5.QtWidgets import QApplication ,QMainWindow,QAction
from os import path
import sys
FORM_CLASS,_= loadUiType(path.join(path.dirname(__file__),"main.ui"))
class MainApp(QMainWindow , FORM_CLASS):
def __init__(self, parent=None):
super(MainApp, self).__init__(parent)
QMainWindow.__init__(self)
self.setupUi(self)
self.idm_UI()
self.idm_Buttons()
def idm_UI(self):
self.setWindowTitle("Download URL")
self.setFixedSize(631,400)
self.setWindowIcon(QIcon("download.jpg"))
# To Create the Icone
exitAct = QAction(QIcon('exit.png'),'Exit',self)
exitAct.triggered.connect(self.idm_exit)
pasteAction = QAction(QIcon("paste.png"), "Add URL", self)
pasteAction.triggered.connect(self.idm_add)
self.toolbar = self.addToolBar('Toolbar')
self.toolbar.addAction(exitAct)
self.toolbar.addAction(pasteAction)
def idm_exit(self):
self.close()
def idm_add(self): # What is the right method that I can use to paste the URL inside lineEdit_4?
pass
The name of define method of function is
def def idm_add(self):
So, what function or method do I need to use to paste the URL inside the LineEditor
box?
What you are to paste the text that is stored in the clipboard, for this you must use
QClipboard
.