Никита Пфейфер Asked:2022-08-10 23:09:13 +0000 UTC2022-08-10 23:09:13 +0000 UTC 2022-08-10 23:09:13 +0000 UTC 如何为按钮添加超链接? 772 是否可以通过Qt Designer程序以某种方式向按钮添加超链接? https://isstatic.askoverflow.dev/YbFsP.jpg 这条线是什么? python 1 个回答 Voted Best Answer S. Nick 2022-08-11T05:00:34Z2022-08-11T05:00:34Z bool QDesktopServices:: openUrl (const QUrl &url) 为用户桌面环境打开URL-адрес指定的网络浏览器,True成功则返回;否则返回False。 如果它URL-адрес是指向本地文件的链接(即 URL 方案是“文件”),那么它将在适当的应用程序而不是 Web 浏览器中打开。 试试这样: q1316237.ui <?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>MainWindow</class> <widget class="QMainWindow" name="MainWindow"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>292</width> <height>234</height> </rect> </property> <property name="windowTitle"> <string>MainWindow</string> </property> <widget class="QWidget" name="centralwidget"> <layout class="QHBoxLayout" name="horizontalLayout"> <item> <widget class="QPushButton" name="pushButton"> <property name="styleSheet"> <string notr="true">QPushButton { border: none; /* Удалить границу */ } #pushButton { background-color: #2196f3; /* Ограничьте минимальный размер */ min-width: 96px; max-width: 96px; min-height: 96px; max-height: 96px; border-radius: 48px; /* круглый */ } #pushButton:hover { background-color: #64b5f6; } #pushButton:pressed { background-color: #bbdefb; }</string> </property> <property name="text"> <string>Мой questions</string> </property> </widget> </item> </layout> </widget> <widget class="QMenuBar" name="menubar"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>292</width> <height>21</height> </rect> </property> </widget> <widget class="QStatusBar" name="statusbar"/> </widget> <resources/> <connections/> </ui> 主文件 import sys from PyQt5 import QtCore, QtGui, QtWidgets, uic qtCreatorFile = "q1316237.ui" Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile) class MyApp(QtBaseClass, Ui_MainWindow): def __init__(self): super().__init__() self.setupUi(self) self.pushButton.clicked.connect(self.on_link) def on_link(self): url = 'https://ru.stackoverflow.com/questions/1316237' QtGui.QDesktopServices.openUrl(QtCore.QUrl(url)) if __name__ == "__main__": app = QtWidgets.QApplication(sys.argv) window = MyApp() window.show() sys.exit(app.exec_()) 更新 你是怎么把按钮弄圆的? 样式表: QPushButton { border: none; /* Удалить границу */ } #pushButton { background-color: #2196f3; /* Ограничьте минимальный размер */ min-width: 96px; max-width: 96px; min-height: 96px; max-height: 96px; border-radius: 48px; /* круглый */ } #pushButton:hover { background-color: #64b5f6; } #pushButton:pressed { background-color: #bbdefb; }
试试这样:
q1316237.ui
主文件
更新
样式表: