PDA

View Full Version : launching animated window from already open window



krystosan
11th December 2013, 18:30
I managed to animate open a window on startup, but I want to open a different window from already open window by pressing the button, in my case already open window is open in fullscreen mode with window.raise_()

Not sure but is this why the window I am trying to animate open by pressing a button is not opening

from PyQt4 import QtCore,QtGui

import sys

class WindLauncher(QtGui.QMainWindow):
""" docstring for WindLauncher
"""
def __init__(self):
super(WindLauncher, self).__init__()
self.btn = QtGui.QPushButton("Launch")
self.btn.clicked.connect(self.launchWin)
self.setCentralWidget(self.btn)


def launchWin(self):
main = MyTableView()
sw = QtGui.QDesktopWidget().screenGeometry(main).width( )
sh = QtGui.QDesktopWidget().screenGeometry(main).height ()
animation = QtCore.QPropertyAnimation(main, "geometry")
animation.setDuration(500);
animation.setStartValue(QtCore.QRect(0, -(sh), sw, sh));
animation.setEndValue(QtCore.QRect(0, 0, sw, sh));
animation.start();
self.show()
self.raise_()

class MyTableView(QtGui.QTableView):
"""docstring for MyTableView"""
def __init__(self, parent=None):
super(MyTableView, self).__init__(parent)


if __name__ == "__main__":
application = QtGui.QApplication(sys.argv)
main = WindLauncher()
main.show()
main.raise_()
sys.exit(application.exec_())

ChrisW67
12th December 2013, 04:10
What are the values of sw and sh at lines 17 and 18? What screen is an unshown widget on?

krystosan
12th December 2013, 14:49
What are the values of sw and sh at lines 17 and 18? What screen is an unshown widget on?

Looking at that I updated my code but still it seems doesn't work, I just see a flickr



from PyQt4 import QtCore,QtGui
from functools import partial
import sys

class MyTableView(QtGui.QTableView):
"""docstring for MyTableView"""
def __init__(self, parent=None):
super(MyTableView, self).__init__(parent)
self.showFullScreen()
sw = QtGui.QDesktopWidget().screenGeometry(self).width( )
sh = QtGui.QDesktopWidget().screenGeometry(self).height ()
self.setGeometry(QtCore.QRect(0, -(sh), sw, sh))

class WindLauncher(QtGui.QMainWindow):
""" docstring for WindLauncher
"""
def __init__(self):
super(WindLauncher, self).__init__()
self.btn = QtGui.QPushButton("Launch")
sw = QtGui.QDesktopWidget().screenGeometry(self).width( )
sh = QtGui.QDesktopWidget().screenGeometry(self).height ()
callLaunch = partial(self.launchWin, sw, sh)
self.btn.clicked.connect(callLaunch)
self.setCentralWidget(self.btn)

def launchWin(self, sw, sh):
main = MyTableView()
animation = QtCore.QPropertyAnimation(main, "geometry")
animation.setDuration(500);
animation.setStartValue(QtCore.QRect(0, -(sh), sw, sh));
animation.setEndValue(QtCore.QRect(0, 0, sw, sh));
animation.start();
main.show()
main.raise_()

if __name__ == "__main__":
application = QtGui.QApplication(sys.argv)
main = WindLauncher()
main.show()
main.raise_()
sys.exit(application.exec_())

ChrisW67
12th December 2013, 23:02
I am not a Python programmer but I expect that the local variable "main" in goes out of scope at the end of the function taking the table widget with it. Same for the "animation" object. Try "self.main" and "self.animation"

krystosan
13th December 2013, 01:12
yes, thats it. thanks. however why does the window that has button stays on top , when i have self.main.raise_() for new animating window ?

ChrisW67
13th December 2013, 03:38
Take a look at QWidget::activateWindow() and the notes about Windows

krystosan
15th December 2013, 13:06
I have got things working but animation doesn't seems to be smooth, is it because the new window is accessing the same QAbstractListModel or something else I need to add to QPropertyAnimation ?