dodle
May 1st, 2009, 05:45 AM
I have become familiar with wxPython and created an application with it. I would now like to create a version using Qt so that it integrates well with KDE, but I'm having trouble getting started. Creating the tabbed interface has got me stuck. How do I add widgets to a tab?
Here is the code I have so far:
import os, sys
from PyQt4 import QtGui, QtCore
class MainWindow(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self)
self.setGeometry(0,0, 500,650)
self.setWindowTitle("Debreate")
self.setWindowIcon(QtGui.QIcon("icon.png"))
self.resize(500,650)
self.setMinimumSize(500,650)
self.center()
# --- Menu --- #
open = QtGui.QAction("Exit", self)
save = QtGui.QAction("Save", self)
build = QtGui.QAction("Build", self)
exit = QtGui.QAction("Quit", self)
menu_bar = QtGui.QMenuBar()
file = menu_bar.addMenu("&File")
help = menu_bar.addMenu("&Help")
file.addAction(open)
file.addAction(save)
file.addAction(build)
file.addAction(exit)
tabs = QtGui.QTabWidget(self)
tab_bar = QtGui.QTabBar(tabs)
tab_1 = tab_bar.addTab("Main")
tab_2 = tab_bar.addTab("Description")
vbox = QtGui.QVBoxLayout()
vbox.addWidget(menu_bar)
vbox.addWidget(tabs)
self.setLayout(vbox)
def center(self):
screen = QtGui.QDesktopWidget().screenGeometry()
size = self.geometry()
self.move((screen.width()-size.width())/2, (screen.height()-size.height())/2)
app = QtGui.QApplication(sys.argv)
frame = MainWindow()
frame.show()
sys.exit(app.exec_())
I've been going over Qt's references but I'm having trouble. There are a few tutorials at http://zetcode.com/tutorials/pyqt4/, but they are somewhat limited. Does anyone know of any other good tutorials or references?
Here is the code I have so far:
import os, sys
from PyQt4 import QtGui, QtCore
class MainWindow(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self)
self.setGeometry(0,0, 500,650)
self.setWindowTitle("Debreate")
self.setWindowIcon(QtGui.QIcon("icon.png"))
self.resize(500,650)
self.setMinimumSize(500,650)
self.center()
# --- Menu --- #
open = QtGui.QAction("Exit", self)
save = QtGui.QAction("Save", self)
build = QtGui.QAction("Build", self)
exit = QtGui.QAction("Quit", self)
menu_bar = QtGui.QMenuBar()
file = menu_bar.addMenu("&File")
help = menu_bar.addMenu("&Help")
file.addAction(open)
file.addAction(save)
file.addAction(build)
file.addAction(exit)
tabs = QtGui.QTabWidget(self)
tab_bar = QtGui.QTabBar(tabs)
tab_1 = tab_bar.addTab("Main")
tab_2 = tab_bar.addTab("Description")
vbox = QtGui.QVBoxLayout()
vbox.addWidget(menu_bar)
vbox.addWidget(tabs)
self.setLayout(vbox)
def center(self):
screen = QtGui.QDesktopWidget().screenGeometry()
size = self.geometry()
self.move((screen.width()-size.width())/2, (screen.height()-size.height())/2)
app = QtGui.QApplication(sys.argv)
frame = MainWindow()
frame.show()
sys.exit(app.exec_())
I've been going over Qt's references but I'm having trouble. There are a few tutorials at http://zetcode.com/tutorials/pyqt4/, but they are somewhat limited. Does anyone know of any other good tutorials or references?