I want to create PYQGIS plugin and for my task i need my QGIS GUI form to have one more button except to original button ok.
the additional button to do something and original button to do something else for my script.
first i add new button in initGui
:
def initGui(self):
icon_path = ':/plugins/twoobutton/icon.png'
self.add_action(
icon_path,
text=self.tr(u'twoobutton'),
callback=self.run,
parent=self.iface.mainWindow())
self.dlg.pushButton.clicked.connect(self.run1)
and after I create new def run1
:
def run1(self):
self.dlg.show()
result = self.dlg.exec_()
if result:
myvar = str(self.dlg.lineEdit_5.text())
if myvar==1000:
text1='hello'
text2='world'
self.dockWidget.dockWidgetContents.lineEdit.setText(str(text1))
self.dockWidget.dockWidgetContents.lineEdit_2.setText(str(text2))
pass
update :
class fff:
"""QGIS Plugin Implementation."""
def __init__(self, iface):
self.dlg = fffDialog()
self.dlg.pushButton.clicked.connect(self.run1)
"""Constructor.
:param iface: An interface instance that will be passed to this class
which provides the hook by which you can manipulate the QGIS
application at run time.
:type iface: QgsInterface
"""
# Save reference to the QGIS interface
self.iface = iface
# initialize plugin directory
self.plugin_dir = os.path.dirname(__file__)
# initialize locale
locale = QSettings().value('locale/userLocale')[0:2]
locale_path = os.path.join(
self.plugin_dir,
'i18n',
'fff_{}.qm'.format(locale))
if os.path.exists(locale_path):
self.translator = QTranslator()
self.translator.load(locale_path)
if qVersion() > '4.3.3':
QCoreApplication.installTranslator(self.translator)
# Declare instance attributes
self.actions = []
self.menu = self.tr(u'&ffffff')
# TODO: We are going to let the user set this up in a future iteration
self.toolbar = self.iface.addToolBar(u'fff')
self.toolbar.setObjectName(u'fff')
But if I click on pushbutton then don't show me anything. How to fix that?