[PyQt] Customizing QSplitter and splitter handle..

Rathinam Signup tfa.signup.test at gmail.com
Sat Feb 11 03:31:07 GMT 2017


Hi Phil,

>From the docs I read that

> You will probably also want to set at least one of the scroll bar modes to AlwaysOn.
>
> All widgets set here will be deleted by the scroll area when it is
> destroyed unless you separately reparent the widget after setting some
> other corner widget (or 0).


It's a strange behavior that, when I resize the widget it disappears. Are
the scroll areas get destroyed when such resizing happens? Is that a bug?
Why my question alone went unanswered? Can you please help me?

- TFA

<https://www.riverbankcomputing.com/mailman/listinfo/pyqt>
> <pyqt-request at riverbankcomputing.com> <pyqt-owner at riverbankcomputing.com>I'm
> posting the question here again since the people here might've failed
> to notice it before. I'm trying to display files and folders like column
> view in Mac finder.
>
> [image: Inline image 1]
>
> I was able get the basic structure with the help of ListViews and
> QFileSystemModel. Then I set the splitter handle as a corner widget for the
> scroll area. I encounter two issues here
>
>    - When I resize the listview, the splitter handle disappears.
>    - Even after setting the splitter handle width to 0, I see spacing
>    between listviews.
>
> Please refer the code below
>
> # -*- coding: utf-8 -*-
>
> from PyQt4 import QtCore, QtGuiimport os
> try:
>     _fromUtf8 = QtCore.QString.fromUtf8
> except AttributeError:
>     def _fromUtf8(s):
>         return s
> try:
>     _encoding = QtGui.QApplication.UnicodeUTF8
>     def _translate(context, text, disambig):
>         return QtGui.QApplication.translate(context, text, disambig,
> _encoding)
> except AttributeError:
>     def _translate(context, text, disambig):
>         return QtGui.QApplication.translate(context, text, disambig)
> class PopulateList(QtGui.QDialog):
>     def __init__(self,parent=None):
>         super().__init__(parent)
>         self.ui = Ui_Form()
>         self.ui.setupUi(self)
>         self.setModel()
>         self.show()
>
>         self.ui.splitter.setHandleWidth(0)#not working
>         self.ui.listView.setVerticalScrollBarPolicy(
> QtCore.Qt.ScrollBarAlwaysOn)
>         self.ui.listView.setCornerWidget(self.getCornerWidget(self.ui.
> splitter))
>
>         self.ui.closePushButton.clicked.connect(self.close)
>         self.ui.listView.clicked.connect(self.showSubFiles)
>
>     def getCornerWidget(self, splitter):
>         self.handle=splitter.handle(1)
>         layout=QtGui.QHBoxLayout(self.handle)
>         layout.setSpacing(0)
>         layout.setMargin(0)
>
>         for i in range(0,2):
>             line = QtGui.QFrame(self.handle)
>             line.setFrameShape(QtGui.QFrame.VLine)
>             layout.addWidget(line)
>
>         return self.handle
>
>     def showSubFiles(self, index):
>         root_path = self.model.fileInfo(index).absoluteFilePath()
>         self.model1=QtGui.QFileSystemModel()
>         self.model1.setRootPath(root_path)
>         self.ui.listView_1.setModel(self.model1)
>         self.ui.listView_1.setRootIndex(self.model1.index(root_path))
>
>     def setModel(self):
>         root_path=os.path.expanduser("~")
>         self.model=QtGui.QFileSystemModel()
>         self.model.setRootPath(root_path)
>         self.model.setFilter(QtCore.QDir.NoDotAndDotDot |
> QtCore.QDir.Dirs)
>         self.ui.listView.setModel(self.model)
>         self.ui.listView.setRootIndex(self.model.index(root_path))
> class Ui_Form(object):
>     def setupUi(self, Form):
>         Form.setObjectName(_fromUtf8("Form"))
>         Form.resize(602, 365)
>         self.verticalLayout = QtGui.QVBoxLayout(Form)
>         self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
>         self.splitter = QtGui.QSplitter(Form)
>         self.splitter.setOrientation(QtCore.Qt.Horizontal)
>         self.splitter.setObjectName(_fromUtf8("splitter"))
>         self.listView = QtGui.QListView(self.splitter)
>         self.listView.setObjectName(_fromUtf8("listView"))
>         self.listView_1 = QtGui.QListView(self.splitter)
>         self.listView_1.setObjectName(_fromUtf8("listView_1"))
>         self.verticalLayout.addWidget(self.splitter)
>         self.horizontalLayout = QtGui.QHBoxLayout()
>         self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
>         spacerItem = QtGui.QSpacerItem(40, 20,
> QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
>         self.horizontalLayout.addItem(spacerItem)
>         self.closePushButton = QtGui.QPushButton(Form)
>         self.closePushButton.setObjectName(_fromUtf8("closePushButton"))
>         self.horizontalLayout.addWidget(self.closePushButton)
>         self.verticalLayout.addLayout(self.horizontalLayout)
>         self.verticalLayout.setStretch(0, 1)
>
>         self.retranslateUi(Form)
>         QtCore.QMetaObject.connectSlotsByName(Form)
>
>     def retranslateUi(self, Form):
>         Form.setWindowTitle(_translate("Form", "Form", None))
>         self.closePushButton.setText(_translate("Form", "Close", None))
>
> if __name__ == "__main__":
>     import sys
>     app = QtGui.QApplication(sys.argv)
>     listView=PopulateList()
>     sys.exit(app.exec_())
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/
> 20170209/cc9a0db7/attachment.html>
> -------------- next part --------------
> A non-text attachment was scrubbed...
> Name: image.png
> Type: image/png
> Size: 28914 bytes
> Desc: not available
> URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/
> 20170209/cc9a0db7/attachment.png>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20170211/37d4f1f9/attachment-0001.html>


More information about the PyQt mailing list