1 Attachment(s)
Customizing splitter handle..
I'm trying to display files and folders like column view in Mac finder. See Image. Attachment 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
Code:
# -*- coding: utf-8 -*-
from PyQt4 import QtCore, QtGui
import os
try:
_fromUtf8
= QtCore.
QString.
fromUtf8except AttributeError:
def _fromUtf8(s):
return s
try:
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
)
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.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.setObjectName(_fromUtf8("verticalLayout"))
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.setObjectName(_fromUtf8("horizontalLayout"))
self.horizontalLayout.addItem(spacerItem)
self.closePushButton.setObjectName(_fromUtf8("closePushButton"))
self.horizontalLayout.addWidget(self.closePushButton)
self.verticalLayout.addLayout(self.horizontalLayout)
self.verticalLayout.setStretch(0, 1)
self.retranslateUi(Form)
def retranslateUi(self, Form):
Form.setWindowTitle(_translate("Form", "Form", None))
self.closePushButton.setText(_translate("Form", "Close", None))
if __name__ == "__main__":
import sys
listView=PopulateList()
sys.exit(app.exec_())
Re: Customizing splitter handle..
From the docs
Quote:
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.
Quote:
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.
Re: Customizing splitter handle..
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?
Re: Customizing splitter handle..
Quote:
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.
Re: Customizing splitter handle..
Quote:
Originally Posted by
d_stranz
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.