![](/img/trans.png)
[英]In a Django Forms drop-down list, how do I show text accessed via a foreign key?
[英]How to do custom drop-down list in QGIS plugin ( PYQT ) like identify tool
我目前正在開發 Qgis Python 插件,現在我需要請求用戶從列表中輸入一個項目。 但我不知道如何制作自定義下拉列表,我通過 inte.net 進行了研究,但找不到解決方案,你能幫我制作一個自定義下拉列表嗎?識別工具 QGIS ( )
我嘗試使用 combobox 小部件來做,但我需要一個列表來選擇項目,你能幫我解決這個問題嗎,我附上了示例列表的照片
我相信前面的問題有你的答案: Qt/PyQt: How do I create a drop down widget, such as a QLabel, QTextBrowser, etc.?
歸功於 ekhumoro:
這是他的代碼:
from PyQt5 import QtGui, QtCore
class Window(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self)
layout = QtGui.QHBoxLayout(self)
self.button = QtGui.QToolButton(self)
self.button.setPopupMode(QtGui.QToolButton.MenuButtonPopup)
self.button.setMenu(QtGui.QMenu(self.button))
self.textBox = QtGui.QTextBrowser(self)
action = QtGui.QWidgetAction(self.button)
action.setDefaultWidget(self.textBox)
self.button.menu().addAction(action)
layout.addWidget(self.button)
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
window = Window()
window.resize(100, 60)
window.show()
sys.exit(app.exec_())
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.