PyQT - Resizing the columns in QListViews
Adam Widera
widera at zeus.polsl.gliwice.pl
Thu Mar 7 17:39:12 EST 2002
I have the following problem:
How to make the columns of QListViews to have the same size as the left
panel
and change their size automatically during the movement of the splitter in
the
exmaple below? THX 4 All hlp.
Adam Widera
PS: If the solution of this problem is too long or too obvious to be placed
on
this list just point me to a similar example on the net.
import sys
from qt import *
class Test(QWidget):
def __init__(self, parent=None, name='Test', f=0):
QWidget.__init__(self, parent, name, f)
def paintEvent(self, e):
p = QPainter(self)
p.setClipRect(e.rect())
class MainWindow(QMainWindow):
def __init__(self, *args):
apply(QMainWindow.__init__, (self,) + args)
self.s1 = QSplitter(Qt.Horizontal, self, "split1")
self.s2 = QSplitter(Qt.Vertical, self.s1, "split2")
self.tree = QListView(self.s2)
self.tree.addColumn("item")
self.tree.setRootIsDecorated(1)
self.items=[]
self.items.append(QListViewItem(self.tree, "root"))
self.items.append(QListViewItem(self.items[-1], "leaf"))
self.items.append(QListViewItem(self.items[-2], "leaf"))
self.tree2 = QListView(self.s2)
self.tree2.addColumn("item")
self.tree2.setRootIsDecorated(1)
self.items2=[]
self.items2.append(QListViewItem(self.tree2, "root"))
self.items2.append(QListViewItem(self.items2[-1], "leaf"))
self.items2.append(QListViewItem(self.items2[-2], "leaf"))
self.t2 = Test(self.s1)
self.t2.setBackgroundColor(Qt.white)
self.s1.setOpaqueResize(1)
self.s2.setOpaqueResize(1)
self.setCentralWidget(self.s1)
def main(args):
app=QApplication(args)
win=MainWindow()
win.show()
app.connect(app, SIGNAL("lastWindowClosed()"),
app, SLOT("quit()"))
app.exec_loop()
if __name__=="__main__":
main(sys.argv)
More information about the Python-list
mailing list