#!/usr/bin/env python #------------------------------------------------------------------------------ # # The Python translation of SoQt-1.2.0/test-code/components/scrollview.py # #-- ORIGINAL COPYRIGHT NOTICE ------------------------------------------------- # # This file is part of the Coin 3D visualization library. # Copyright (C) 1998-2004 by Systems in Motion. All rights reserved. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # ("GPL") version 2 as published by the Free Software Foundation. # See the file LICENSE.GPL at the root directory of this source # distribution for additional information about the GNU GPL. # # For using Coin with software that can not be combined with the GNU # GPL, and for taking advantage of the additional benefits of our # support services, please contact Systems in Motion about acquiring # a Coin Professional Edition License. # # See <URL:http://www.coin3d.org/> for more information. # # Systems in Motion, Teknobyen, Abels Gate 5, 7030 Trondheim, NORWAY. # <URL:http://www.sim.no/>. # #------------------------------------------------------------------------------ # # Demonstrates embedding of an SoQtRenderArea within a QScrollView. # #------------------------------------------------------------------------------ from iv import * from qt import * import sys class MyScrollView(QScrollView): def __init__(self, parent): QScrollView.__init__(self, parent) self.resizeContents(10000, 10000) self.enableClipper(True) # Container widget for the SoQtRenderArea. container = QWidget(self) container.resize(1000, 1000) # Construct a simple scenegraph. root = SoSeparator() light = SoDirectionalLight() light.direction.setValue(-0.5, -0.5, -0.8) root.addChild(light) camera = SoPerspectiveCamera() camera.orientation.setValue(SbRotation(SbVec3f(0, 0, 1), 0)) root.addChild(camera) cone = SoCone() root.addChild(cone) # Add the renderarea. self.renderarea = SoQtRenderArea(container) self.renderarea.setSceneGraph(root) camera.viewAll(root, self.renderarea.getViewportRegion()) self.addChild(container, 100, 100) container.show() self.renderarea.show() # __init__() # WARNING: advanced PyQt programming: # Since the virtual C++ member function drawContents() is overloaded in # in the inheritance tree of QScrollView, it may be called as: # 1. QFrame.drawContents(painter) # 2. QScrollView.drawContents(painter, cx, cy, cw, ch) # Therefore, the Python call must be able to handle 2 and 6 arguments. def drawContents(self, *args): if len(args) == 5: painter, cx, cy, cw, ch = args painter.fillRect(cx, cy, cw, ch, QBrush(QColor(40, 80, 0))) self.renderarea.scheduleRedraw() # drawContents() # class MyScrollView def main(): # Initialize Qt and SoQt. app = QApplication(sys.argv) SoQt.init(None) # Set up scrollview window. view = MyScrollView(None) view.viewport().setBackgroundMode(QWidget.NoBackground) # Map window. view.show() # Set termination condition. QObject.connect( qApp, SIGNAL('lastWindowClosed()'), qApp, SLOT('quit()')) # Start event loop. SoQt.mainLoop() # main() if __name__ == '__main__': main() # Local Variables: *** # mode: python *** # End: ***