EddieH
EddieH

Reputation: 65

User resizing PyQt widgets

I'm very new to PyQt and Python, so hopefully this question makes sense.

I have a QTreeView, QListView and QTextEdit set next to one another in a column like format. As a user, lets say I'd like to alter the width of one of the columns. How do I go about achieving this? If you're a user of Maya, imagine a paneLayout, this is what I'm trying to achieve.

Example:

[1][2][3]
[   1  ][2][3]
[1][   2   ][ 3 ]

...rather than just resizing the whole window. I hope this makes sense...!

Thanks to anyone who can help!

Upvotes: 2

Views: 4672

Answers (1)

Gary Hughes
Gary Hughes

Reputation: 4510

I'm not a Maya user so I don't know what a paneLayout is, but it sounds like what you're looking for can be achieved with a QSplitter (see here or here).

Here's a quick example:

from PyQt4.QtGui import QWidget, QApplication, QTreeView, QListView, QTextEdit, \
                        QSplitter, QHBoxLayout

import sys

class MainWindow(QWidget):
    def __init__(self):
        QWidget.__init__(self)

        treeView = QTreeView()
        listView = QListView()
        textEdit = QTextEdit()
        splitter = QSplitter(self)

        splitter.addWidget(treeView)
        splitter.addWidget(listView)
        splitter.addWidget(textEdit)

        layout = QHBoxLayout()
        layout.addWidget(splitter)
        self.setLayout(layout)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    mainWindow = MainWindow()
    mainWindow.show()
    sys.exit(app.exec_())

Upvotes: 7

Related Questions