I need your help I am developing a dialog box (which I will call toolraster) in QGis to interact with raster layers. I want it to display when I click on a menu I insert in the QGis interface.
I created Toolraster as a class that extends QtWidgets, a QWidget. Create the QAction and connect it to the toolraster instance function. Create the submenu with iface.pluginMenu().addSeparator() and iface.pluginMenu().addAction(activar). Example below.
The problem: when I run the menu the dialog box opens and closes instantly. It doesn't report any errors
When I perform the same procedure with a QInputDialog or a QMessageBox it doesn't present any problems.
But with a class like this it is a problem:
from qgis import PyQt
from qgis.PyQt import QtWidgets
class test(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("clase de prueba")
layout = QVBoxLayout()
widgets = [QCheckBox,
QComboBox,
QDateEdit,
QDateTimeEdit,
QDial,
QDoubleSpinBox]
for w in widgets:
layout.addWidget(w())
self.setLayout(layout)
def activar():
h=test()
h.show()
test_action=QAction("Menu de prueba")
test_action.triggered.connect(activar)
iface.pluginMenu().addSeparator()
iface.pluginMenu().addAction(test_action)
Note: when I execute the function activar() in the console the same thing happens, if I insert the show() inside the class too