Results 1 to 5 of 5

Thread: Customizing splitter handle..

  1. #1
    Join Date
    Feb 2017
    Posts
    6
    Qt products
    Platforms
    MacOS X Unix/X11 Windows

    Default Customizing splitter handle..

    I'm trying to display files and folders like column view in Mac finder. See Image. Screen Shot 2017-02-07 at 6.00.16 pm.png
    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
    Qt Code:
    1. # -*- coding: utf-8 -*-
    2.  
    3. from PyQt4 import QtCore, QtGui
    4. import os
    5.  
    6. try:
    7. _fromUtf8 = QtCore.QString.fromUtf8
    8. except AttributeError:
    9. def _fromUtf8(s):
    10. return s
    11.  
    12. try:
    13. _encoding = QtGui.QApplication.UnicodeUTF8
    14. def _translate(context, text, disambig):
    15. return QtGui.QApplication.translate(context, text, disambig, _encoding)
    16. except AttributeError:
    17. def _translate(context, text, disambig):
    18. return QtGui.QApplication.translate(context, text, disambig)
    19.  
    20. class PopulateList(QtGui.QDialog):
    21. def __init__(self,parent=None):
    22. super().__init__(parent)
    23. self.ui = Ui_Form()
    24. self.ui.setupUi(self)
    25. self.setModel()
    26. self.show()
    27.  
    28. self.ui.splitter.setHandleWidth(0)#not working
    29. self.ui.listView.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
    30. self.ui.listView.setCornerWidget(self.getCornerWidget(self.ui.splitter))
    31.  
    32. self.ui.closePushButton.clicked.connect(self.close)
    33. self.ui.listView.clicked.connect(self.showSubFiles)
    34.  
    35. def getCornerWidget(self, splitter):
    36. self.handle=splitter.handle(1)
    37. layout=QtGui.QHBoxLayout(self.handle)
    38. layout.setSpacing(0)
    39. layout.setMargin(0)
    40.  
    41. for i in range(0,2):
    42. line = QtGui.QFrame(self.handle)
    43. line.setFrameShape(QtGui.QFrame.VLine)
    44. layout.addWidget(line)
    45.  
    46. return self.handle
    47.  
    48. def showSubFiles(self, index):
    49. root_path = self.model.fileInfo(index).absoluteFilePath()
    50. self.model1=QtGui.QFileSystemModel()
    51. self.model1.setRootPath(root_path)
    52. self.ui.listView_1.setModel(self.model1)
    53. self.ui.listView_1.setRootIndex(self.model1.index(root_path))
    54.  
    55. def setModel(self):
    56. root_path=os.path.expanduser("~")
    57. self.model=QtGui.QFileSystemModel()
    58. self.model.setRootPath(root_path)
    59. self.model.setFilter(QtCore.QDir.NoDotAndDotDot | QtCore.QDir.Dirs)
    60. self.ui.listView.setModel(self.model)
    61. self.ui.listView.setRootIndex(self.model.index(root_path))
    62.  
    63. class Ui_Form(object):
    64. def setupUi(self, Form):
    65. Form.setObjectName(_fromUtf8("Form"))
    66. Form.resize(602, 365)
    67. self.verticalLayout = QtGui.QVBoxLayout(Form)
    68. self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
    69. self.splitter = QtGui.QSplitter(Form)
    70. self.splitter.setOrientation(QtCore.Qt.Horizontal)
    71. self.splitter.setObjectName(_fromUtf8("splitter"))
    72. self.listView = QtGui.QListView(self.splitter)
    73. self.listView.setObjectName(_fromUtf8("listView"))
    74. self.listView_1 = QtGui.QListView(self.splitter)
    75. self.listView_1.setObjectName(_fromUtf8("listView_1"))
    76. self.verticalLayout.addWidget(self.splitter)
    77. self.horizontalLayout = QtGui.QHBoxLayout()
    78. self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
    79. spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
    80. self.horizontalLayout.addItem(spacerItem)
    81. self.closePushButton = QtGui.QPushButton(Form)
    82. self.closePushButton.setObjectName(_fromUtf8("closePushButton"))
    83. self.horizontalLayout.addWidget(self.closePushButton)
    84. self.verticalLayout.addLayout(self.horizontalLayout)
    85. self.verticalLayout.setStretch(0, 1)
    86.  
    87. self.retranslateUi(Form)
    88. QtCore.QMetaObject.connectSlotsByName(Form)
    89.  
    90. def retranslateUi(self, Form):
    91. Form.setWindowTitle(_translate("Form", "Form", None))
    92. self.closePushButton.setText(_translate("Form", "Close", None))
    93.  
    94.  
    95. if __name__ == "__main__":
    96. import sys
    97. app = QtGui.QApplication(sys.argv)
    98. listView=PopulateList()
    99. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Feb 2017
    Posts
    6
    Qt products
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Customizing splitter handle..

    From the docs
    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.

  3. #3
    Join Date
    Feb 2017
    Posts
    6
    Qt products
    Platforms
    MacOS X Unix/X11 Windows

    Default 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?

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,193
    Thanks
    236
    Thanked 667 Times in 657 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Customizing splitter handle..

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #5
    Join Date
    Feb 2017
    Posts
    6
    Qt products
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Customizing splitter handle..

    Quote Originally Posted by d_stranz View Post
    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.

Similar Threads

  1. thin splitter
    By nikkymen in forum Qt Programming
    Replies: 1
    Last Post: 31st August 2011, 10:16
  2. Replies: 1
    Last Post: 22nd November 2008, 07:32
  3. Automatic Splitter
    By Katuakina in forum Qt Tools
    Replies: 1
    Last Post: 5th October 2007, 10:29
  4. Splitter?
    By Katuakina in forum Qt Programming
    Replies: 1
    Last Post: 5th October 2007, 10:21
  5. splitter
    By gambr in forum Qt Tools
    Replies: 2
    Last Post: 21st November 2006, 18:06

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.