<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman,new york,times,serif;font-size:12pt"><div>Hi all,<br><br>I'm new to pyqt and am having a bit of trouble. I'm trying to make a (_very_) simple report designer. Right now I'm just trying to get a feel for what I can do in pyqt and so I've laid out a simple program that represents a document with several bands (if you are familiar with Crystal, you've seen the band style designer I'm trying to emulate). I feel I'm getting closer, but right now i'm just hacking at it so I feel I should ask for some guidance at this point. A few of the issues I'm having are:<br><br>1) Resizer.paintEvent is getting called... a lot. I'm not really sure why.<br>2) When I resize the inner window, i don't wan't contents to resize, but if I don't have the inner widget set to resizable, things are worse. How can I have it both
ways? I guess what I am trying to say is I want the only way to resize a band be via the Resizer (or eventually some scale factor). Not by dragging the window. <br>3) General resizing issues. Top band doesn't get smaller when I drag the Resizer up.<br> When i drag top Resizer down it makes the top one bigger the middle one gets smaller instead of just being pushed down, etc...<br> What can I try in order to get the layouts to function like I envision?<br> <br>Any guidance on what I can try to straighten some of these issues out would be appreciated. Or, if I'm just going about this the wrong way, please let me know (though I've swiped the ideas from several similar projects...)<br><br>Thanks,<br>Lee<br><br>Below is the code (hopefully not too long to post here):<br><br>#!/usr/bin/env python<br> <br>import sys<br>from PyQt4 import QtCore, QtGui<br> <br>class
CustomWidget(QtGui.QWidget):<br> def __init__(self, parent=None):<br> QtGui.QWidget.__init__(self, parent)<br> <br> def paintEvent(self, event):<br> print "paintEvent"<br> paint = QtGui.QPainter()<br> paint.begin(self)<br> size = self.size()<br> w = size.width()<br> h = size.height()<br> pen = QtGui.QPen(QtGui.QColor(20, 20, 20), 1, QtCore.Qt.SolidLine)<br> paint.setPen(pen)<br>
paint.setBrush(QtCore.Qt.NoBrush)<br> paint.drawRect(0, 0, w-1, h-1)<br> paint.end()<br> <br>class Resizer(QtGui.QWidget):<br> def __init__(self, parent=None):<br> QtGui.QWidget.__init__(self,parent)<br> <br> self.setMinimumHeight(5)<br> self.setMaximumHeight(5)<br> self.setCursor(QtGui.QCursor(QtCore.Qt.SizeVerCursor))<br> self.resize(5,50)<br> print "Resizer.__init__"<br> <br> def mouseMoveEvent(self, event):<br>
event.accept()<br> print "here"<br> y = event.y()<br> self.emit(QtCore.SIGNAL('MovedResizer'), y)<br> <br> def paintEvent(self, event):<br> painter = QtGui.QPainter(self)<br> print "here"<br> styles = QtGui.QStyleOption(QtGui.QStyleOption.SO_SizeGrip)<br> styles.initFrom(self)<br> self.style().drawControl(QtGui.QStyle.CE_Splitter, styles, painter, self)<br> self.setBackgroundRole(QtGui.QPalette.Dark)<br> <br> <br>class Band(QtGui.QWidget):<br> def __init__(self,
parent=None):<br> super(Band, self).__init__(parent)<br> self.rb = Resizer()<br> # eventually replace with custom edit control<br> self.lb = CustomWidget()<br> <br> layout = QtGui.QVBoxLayout(self)<br> layout.setMargin(0)<br> layout.setSpacing(0)<br> layout.addWidget(self.lb)<br> layout.addWidget(self.rb) <br> #self.setLayout(layout)<br> self.connect(self.rb, QtCore.SIGNAL('MovedResizer'), self.changeSize
)<br> <br> def changeSize(self, y):<br> print "In changeSize %d" % y<br> h = self.lb.height() + y<br> if h < 1:<br> h = 1<br> print "H = %d" % h<br> self.lb.setMinimumHeight(h)<br> #self.lb.setMaximumHeight(h)<br> #self.lb.resize(self.lb.width(), h)<br> #self.lb.repaint()<br> <br> <br>class Document(QtGui.QWidget):<br> def __init__(self, parent=None):<br> super(Document,
self).__init__(parent)<br> <br> self.outerLayout = QtGui.QVBoxLayout()<br> <br> self.myBands = QtGui.QWidget()<br> self.myBands.setBackgroundRole(QtGui.QPalette.Base)<br> self.layoutBands = QtGui.QVBoxLayout(self.myBands)<br> self.layoutBands.setMargin(0)<br> self.layoutBands.setSpacing(0)<br> <br> self.scrollArea = QtGui.QScrollArea()<br> self.scrollArea.setBackgroundRole(QtGui.QPalette.Dark)<br>
self.scrollArea.setWidget(self.myBands)<br> self.scrollArea.setWidgetResizable(True)<br> <br> self.outerLayout.addWidget(self.myBands)<br> <br> def addBand(self):<br> print "adding band"<br> self.layoutBands.addWidget(Band()) <br> <br> def getScrollArea(self):<br> return self.scrollArea<br> <br>class MyWindow(QtGui.QMainWindow):<br> def __init__(self, parent = None):<br> QtGui.QMainWindow.__init__(self, parent)<br> <br> self.ws =
QtGui.QWorkspace(self)<br> self.ws.setScrollBarsEnabled(True)<br> self.setCentralWidget(self.ws) <br> <br> self.doc = Document()<br> self.doc.addBand()<br> self.doc.addBand()<br> self.doc.addBand()<br> <br> self.ws.addWindow(self.doc.getScrollArea())<br> <br> self.setWindowTitle(self.tr("Doesn't Quite Work"))<br> self.resize(640, 480)<br> <br>if __name__ == "__main__":<br> app =
QtGui.QApplication(sys.argv)<br> myWindow = MyWindow()<br> myWindow.show()<br> sys.exit(app.exec_())<br><br></div></div><br>
</body></html>