PDA

View Full Version : Customizing splitter handle..



tfa
10th February 2017, 13:43
I'm trying to display files and folders like column view in Mac finder. See Image. 12331
I was able get the basic structure with the help of ListViews and QFileSystemModel. Then when 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, QtGui
import 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.getCornerWid get(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(roo t_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.closePushButt on)
self.verticalLayout.addLayout(self.horizontalLayou t)
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_())

tfa
11th February 2017, 04:36
From the docs (http://pyqt.sourceforge.net/Docs/PyQt4/qabstractscrollarea.html#setCornerWidget)

You will probably also want to set at least one of the scroll bar modes to AlwaysOn.
This is the reason why I've set the Vertical scroll bar mode always on.

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).
The scroll bar isn't destroyed. It's still visible and active. But the corner widget disappears. Is that a Qt bug? Please help me solve this issue.

tfa
12th February 2017, 05:49
Is there any other way I can achieve this? Like a floating splitter handle placed on the corner of the vertical scroll area?? Can you please give some pointers?

d_stranz
14th February 2017, 04:30
The scroll bar isn't destroyed.
I think you are confusing the scroll bar with the scroll area. Sorry, but I can't offer a solution.

tfa
14th February 2017, 10:26
I think you are confusing the scroll bar with the scroll area.
@d_stranz I'm afraid you haven't understand my question enough. One of the base class of QListView is QAbstractScrollArea and that's why we could set vertical and horizontal scroll bar policy and my goal here is to set corner widget for the scrollarea. Please let me know if further clarifications required.