Difference between revisions of "User:Axiom"

Jump to: navigation, search
Line 21: Line 21:
  
 
==Connecting Buttons From Dynamically loaded .ui File==
 
==Connecting Buttons From Dynamically loaded .ui File==
 +
 +
This code really works.
  
 
===loaddialog.py===
 
===loaddialog.py===
Line 27: Line 29:
 
from PyQt4 import QtGui
 
from PyQt4 import QtGui
 
from PyQt4 import uic
 
from PyQt4 import uic
 +
from PyQt4 import QtCore
  
 
# the class has to have the same base class as your UI
 
# the class has to have the same base class as your UI
class DemoImpl(QtGui.QDialog):
+
class DemoImpl(QtGui.QMainWindow):
 
     def __init__(self, *args):
 
     def __init__(self, *args):
         QtGui.QWidget.__init__(self, *args)
+
         QtGui.QMainWindow.__init__(self, *args)
 
# just pass self
 
# just pass self
uic.loadUi("demo.ui", self)
+
uic.loadUi("mainWindow.ui", self)
     #for some reason this seems to be called twice       
+
     #this line makes sure that we are only looking for a string
 +
    #if we want a bool as well we can add @QtCore.pyqtSignature("bool")
 +
    @QtCore.pyqtSignature("") 
 
     def on_button1_clicked(self):
 
     def on_button1_clicked(self):
 
         print "You Clicked the button!"
 
         print "You Clicked the button!"
+
    @QtCore.pyqtSignature("")
     def on_pushButton_2_clicked(self):
+
     def on_button2_clicked(self):
 
         print "You Clicked the button2!"
 
         print "You Clicked the button2!"
 
 
 
 
  
Line 48: Line 51:
 
widget.show()
 
widget.show()
 
app.exec_()
 
app.exec_()
 +
  
 
</code>
 
</code>

Revision as of 23:44, 21 January 2007

Contents

Axiom's sandbox

I am just putting some stuff here right now, because you have such nice color coding in your wiki. Maybe I'll turn it into a tutorial if I figure out what I am doing.

Dynamically Loading a .ui file

I found this snippet here (french). I don't know if this is the right way to do it, but it seems to work.

loadui.py

import sys from PyQt4 import QtGui, uic

app = QtGui.QApplication(sys.argv) widget = uic.loadUi("demo.ui") widget.show()

  1. La boucle principale

app.exec_() Of course you will need to make a ui file called demo.ui for this to work.

Connecting Buttons From Dynamically loaded .ui File

This code really works.

loaddialog.py

import sys from PyQt4 import QtGui from PyQt4 import uic from PyQt4 import QtCore

  1. the class has to have the same base class as your UI

class DemoImpl(QtGui.QMainWindow):

   def __init__(self, *args):
       QtGui.QMainWindow.__init__(self, *args)

# just pass self uic.loadUi("mainWindow.ui", self)

   #this line makes sure that we are only looking for a string
   #if we want a bool as well we can add 	@QtCore.pyqtSignature("bool")
   @QtCore.pyqtSignature("")   
   def on_button1_clicked(self):
       print "You Clicked the button!"
   @QtCore.pyqtSignature("")
   def on_button2_clicked(self):
       print "You Clicked the button2!"	


app = QtGui.QApplication(sys.argv) widget = DemoImpl() widget.show() app.exec_()



KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V.Legal