I have a problem. Can I make a link on the web page in the window and when the user clicks on it, the web page will be open in the browser. For example:
import sys
from PyQt4 import QtGui, QtCore
app = QtGui.QApplication(sys.argv)
main = QtGui.QWidget()
main.setGeometry(200, 200, 200, 100)
label = QtGui.QLabel('<a href="http://stackoverflow.com/">Stackoverflow/</a>')
box = QtGui.QVBoxLayout()
box.addWidget(label)
main.setLayout(box)
main.show()
sys.exit(app.exec_())
Is it really?
There's no such thing as a hyperlink in a text file. A text file just has text. You can write syntax for a hyperlink, say using HTML -- is that what you mean? @katrielalex: So you mean that I should create logfile.
If you print a URL to the console, it will get underlined if you hover over it, and if you right-click on it a menu pops up, and one of the menu options is "Open link". You just print it syntactically correct. To identify the hyperlink is the job of the terminal application. – Klaus D.
PyQt is widely used for creating large-scale GUI-based programs. It gives programmers the freedom to create GUIs of their choice while also providing a lot of good pre-built designs. PyQT gives you widgets to create complex GUIs.
The provision of drag and drop is very intuitive for the user. It is found in many desktop applications where the user can copy or move objects from one window to another. MIME based drag and drop data transfer is based on QDrag class.
It is of course good that you found answer, but there is special class, which allows you to open URL in default browser or files in default editors/players etc. It is QDesktopServices
. For example:
from PyQt5.QtGui import QDesktopServices
from PyQt5.QtCore import QUrl
class MainWindow(QMainWindow, Ui_MainWindow):
def link(self, linkStr):
QDesktopServices.openUrl(QUrl(linkStr))
def __init__(self):
super(MainWindow, self).__init__()
# Set up the user interface from Designer.
self.setupUi(self)
self.label.linkActivated.connect(self.link)
self.label.setText('<a href="http://stackoverflow.com/">Stackoverflow/</a>')
This example is definitely larger, but you should know about QDesktopServices
, because it is very useful class.
Sorry. I have already searched the answer.
label.setText('<a href="http://stackoverflow.com/">Link</a>')
label.setOpenExternalLinks(True)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With