简体   繁体   English

如何在 QGIS 插件 ( PYQT ) 中自定义下拉列表,如识别工具

[英]How to do custom drop-down list in QGIS plugin ( PYQT ) like identify tool

I am currently working on a Qgis Python plugin and now I need to request the user to input an item from a list.我目前正在开发 Qgis Python 插件,现在我需要请求用户从列表中输入一个项目。 But I don't know how to make a custom drop-down list, I researched through the inte.net but I can't find a solution for this, can you help me to make a custom drop-down list like Build-in Identify tool QGIS (但我不知道如何制作自定义下拉列表,我通过 inte.net 进行了研究,但找不到解决方案,你能帮我制作一个自定义下拉列表吗?识别工具 QGIS (
点击此处查看图片 ) )

I try to do by using combobox widget but i need a list to choose item, can you please help me to solve this, i attaching the photo of example list我尝试使用 combobox 小部件来做,但我需要一个列表来选择项目,你能帮我解决这个问题吗,我附上了示例列表的照片
点击此处查看图片

I believe this previous question has your answer: Qt/PyQt: How do I create a drop down widget, such as a QLabel, QTextBrowser, etc.?我相信前面的问题有你的答案: Qt/PyQt: How do I create a drop down widget, such as a QLabel, QTextBrowser, etc.?

Credit to ekhumoro:归功于 ekhumoro:

This is his code:这是他的代码:

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