簡體   English   中英

如何在 QGIS 插件 ( PYQT ) 中自定義下拉列表,如識別工具

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM