Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a form that appears when you start the plugin.How do I properly apply to the button on the form, so that when you click on the button performed "function".

import sys,os
import win32api
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
import ctypes
from PyQt4 import uic

class HelloWorld:
   def __init__(self, iface):  
      self.iface = iface
      self.canvas = iface.mapCanvas()

   def initGui(self):  
      pushButton=QPushButton("pushButton")
      self.action = QAction(QIcon(":/plugins/"), "&HelloWorld", self.iface.mainWindow())
      self.action.setWhatsThis("Configuration for test plugin")
      self.action.setStatusTip("This is status tip")
      QObject.connect(self.action, SIGNAL("activated()"), self.hello_world)      
      QObject.connect(pushButton, SIGNAL("clicked()"),self.function)

      self.iface.addPluginToMenu("HelloWorld", self.action)   

   def unload(self):    
      self.iface.removePluginMenu("HelloWorld",self.action)
      self.iface.removeToolBarIcon(self.action)

   def function(self):
      QMessageBox.information(self.iface.mainWindow(), QCoreApplication.translate('HelloWorld', "HelloWorld"), QCoreApplication.translate('HelloWorld', "HelloWorld"))
      return

   def hello_world(self):      
      path = os.path.dirname( os.path.abspath( __file__ ) )
      self.optionsDialog = uic.loadUi(os.path.join(path,"untitled.ui"))
      self.optionsDialog.show()

if __name__ == "__main__":
   pass
share|improve this question
    
Your pushButton variable isn't on the form. You need to add it to your untitled.ui using QtDesigner –  Nathan W May 13 '13 at 7:55
    
I have it there has already been added. it did so. the only question is how to appeal to a button on this form? –  Cathrin May 13 '13 at 8:44
add comment

1 Answer 1

If you want to access the button on the form you can just do:

  self.optionsDialog = uic.loadUi(os.path.join(path,"untitled.ui"))
  self.optionsDialog.pushButton.toggled.connect(self.function)
  self.optionsDialog.show()

pushButton is the objectName of the QPushButton.

share|improve this answer
    
This part of the code should be in the "def hello_world(self)"? –  Cathrin May 13 '13 at 8:52
    
yes inside hello_world() –  Nathan W May 13 '13 at 8:53
    
In "def initGui(self):" No need to change anything ? –  Cathrin May 13 '13 at 8:54
    
well you don't need pushButton=QPushButton("pushButton") or QObject.connect(pushButton, SIGNAL("clicked()"),self.function) in there. –  Nathan W May 13 '13 at 8:55
    
and that, instead, I need to use? –  Cathrin May 13 '13 at 9:00
show 5 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.