[PyQt] A Hopefully Silly Question from a Beginner
patrick at mkii.org
Mon Sep 16 18:18:14 BST 2013
On 09/16/2013 10:58 AM, Ryan Hanson wrote:
> On Mon, Sep 16, 2013 at 10:19 AM, Patrick Barrett <patrick at mkii.org
> <mailto:patrick at mkii.org>> wrote:
> I'm trying to write a small app the generates a few QWebView
> windows and then rotates the page that is displayed on a set interval.
> Code: https://gist.github.com/Azdle/6556433
> I've run into an issue that I don't understand. When I try to
> generate a `PageWindow` (Class based on QWebView) from within my
> `MainWindow` class nothing appears. (See the code in 29-30)
> However, when I copy and paste that code outside of any classes
> the window appears as it should. (See the commented code in 56-57)
> Even when I can make the QWebView window appear, the QTimer object
> that I create in the `PageWindow` never seems to timeout. I think
> this is being caused by the same issue as the first problem.
> I'm not sure if the issues are me doing the python wrong or just
> not understanding something about how the Qt-specfic aspects work.
> I have this application already working in C++, but want to get it
> working in Python.
> Here you go Patrick, you want to move your timer into your main class
> and then call your new page function on the instance of PageWindow
> that you create inside that class.
> import sys
> from PyQt4.QtCore import *
> from PyQt4.QtGui import *
> from PyQt4.QtWebKit import *
> pages = [
> class MainWindow(QMainWindow):
> def __init__(self, *args):
> self.quitButton = QPushButton("Quit")
> vbox = QVBoxLayout()
> centralWidget = QWidget()
> self.pageView = PageWindow()
> self.pageTimer = QTimer()
> def closeEvent(self, event):
> class PageWindow(QWebView):
> def __init__(self):
> self.pageIndex = 0
> def nextPage(self):
> self.pageIndex = self.pageIndex + 1
> if self.pageIndex >= len(pages):
> self.pageIndex = 0
> def main(args):
> app = QApplication(args)
> win = MainWindow()
> app.connect(app, SIGNAL("lastWindowClosed()"),
> app, SLOT("quit()"))
> if __name__=="__main__":
Thanks Ryan. I ended up moving the timer object back into the
Added a new revision to the old Gist: https://gist.github.com/Azdle/6556433
I see from your code that my issue was that I was putting object in
local scope instead of putting them in the object (using var instead of
self.var, my terminology is probably wrong) so the objects were getting
garbage collected right after getting created.
Thanks for your help!
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the PyQt