0

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

JonnyPython
  • 121
  • 1
  • 2
  • 9
  • I think you need to narrow down your question. It's not clear what you're confused about: modules? PyQT4? QtWebKit? OOP? Program design? – Radio- Apr 16 '13 at 18:36
  • Hi thx for reply. I think it has something to do with OOP and PyQt4. I want to know if what i wrote is right. And how can i use the QtWebKit without creating a new class and stuff. Just look at the ?? signs :) – JonnyPython Apr 16 '13 at 18:43

1 Answers1

1

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 *
Radio-
  • 3,151
  • 21
  • 22