简体   繁体   中英

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. 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 (
点击此处查看图片 )

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
点击此处查看图片

I believe this previous question has your answer: Qt/PyQt: How do I create a drop down widget, such as a QLabel, QTextBrowser, etc.?

Credit to 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_())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM