Reputation: 121
I want to do some things with the PyQt4 framework. So I decided to do some browser like thing. Here is the code. Its just simple:
import sys
from PyQt4 import QtGui, QtCore, QtWebKit
class MainWindow(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.resize(250, 150)
self.setWindowTitle('Testbrowser')
exit = QtGui.QAction(QtGui.QIcon('icons/exit.png'), 'Exit', self)
exit.setShortcut('Ctrl+Q')
exit.setStatusTip('Exit application')
self.connect(exit, QtCore.SIGNAL('triggered()'), QtCore.SLOT('close()'))
self.statusBar()
menubar = self.menuBar()
datei = menubar.addMenu('&Datei')
datei.addAction(exit)
tools = menubar.addMenu('&Tools')
app = QtGui.QApplication(sys.argv)
main = MainWindow()
web = QWebView()
web.load(QUrl("http://google.de"))
main.show()
sys.exit(app.exec_())
I think I understood some of the things here. But what I do not understand is, how can I work with new modules here? The MainWindow class inherits from the QtGui.QMainWindow class, thats ok. But what now? Should I create a whole new class which inherits from QWebView?? Kind of like :
class newclass(QWebView.QtWebKit):
def __init__(self):
QWebView.QtWebkit.__init__(self)
ect
Or how can I do this without a new class? Or how do I do this in general? I saw a webpage on which the author made a simple browser too. But he imported it in a new programm and made an object out of it and then did some stuff. Do I have to do this, or is there a simpler way? How is this all done in PyQt4? Greets some reference http://pyqt.sourceforge.net/Docs/PyQt4/qwebview.html
Upvotes: 0
Views: 70
Reputation: 3171
Accessing elements of a module follows a dot notation convention in Python -- e.g. to access QWebView, you should use
web = QtWebkit.QWebView()
the URL would be
QtCore.QUrl("http://google.de")
If you want to have all of the names available to you without dot notation, you have to import everything:
from PyQt4.QtWebkit import *
Upvotes: 1