[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] Customizing QSplitter and splitter handle..
From:       Rathinam Signup <tfa.signup.test () gmail ! com>
Date:       2017-02-11 3:43:07
Message-ID: CAPzkV1zDWADrkoRFMggzfnFgGtYEYJ75Jfwd+uerkq5MMyiiUg () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


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@riverbankcomputing.com> <pyqt-owner@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>
>

[Attachment #5 (text/html)]

<div dir="ltr"><div>Hi Phil,<br><br></div>From the docs I read that<br><blockquote \
class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid \
rgb(204,204,204);padding-left:1ex">You will probably also want to set at least one of \
the scroll bar modes to <tt>AlwaysOn. </tt><br>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).</blockquote><div><div><div><div \
class="gmail_extra"><br></div><div class="gmail_extra">It&#39;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?<br></div><div class="gmail_extra"><div class="gmail_quote"><span \
dir="ltr"></span><br></div><div class="gmail_quote">- TFA<br><br></div><div \
class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><a \
href="https://www.riverbankcomputing.com/mailman/listinfo/pyqt" rel="noreferrer" \
target="_blank"><wbr><wbr></a><a \
href="mailto:pyqt-request@riverbankcomputing.com"><wbr></a><a \
href="mailto:pyqt-owner@riverbankcomputing.com"><wbr></a>I&#39;m posting the question \
here again since the people here might&#39;ve failed<br> to notice it before. I&#39;m \
trying to display files and folders like column<br> view in Mac finder.<br>
<br>
[image: Inline image 1]<br>
<br>
I was able get the basic structure with the help of ListViews and<br>
QFileSystemModel. Then I set the splitter handle as a corner widget for the<br>
scroll area. I encounter two issues here<br>
<br>
     - When I resize the listview, the splitter handle disappears.<br>
     - Even after setting the splitter handle width to 0, I see spacing<br>
     between listviews.<br>
<br>
Please refer the code below<br>
<br>
# -*- coding: utf-8 -*-<br>
<br>
from PyQt4 import QtCore, QtGuiimport os<br>
try:<br>
      _fromUtf8 = QtCore.QString.fromUtf8<br>
except AttributeError:<br>
      def _fromUtf8(s):<br>
            return s<br>
try:<br>
      _encoding = QtGui.QApplication.UnicodeUTF8<br>
      def _translate(context, text, disambig):<br>
            return QtGui.QApplication.translate(<wbr>context, text, disambig, \
_encoding)<br> except AttributeError:<br>
      def _translate(context, text, disambig):<br>
            return QtGui.QApplication.translate(<wbr>context, text, disambig)<br>
class PopulateList(QtGui.QDialog):<br>
      def __init__(self,parent=None):<br>
            super().__init__(parent)<br>
            self.ui = Ui_Form()<br>
            self.ui.setupUi(self)<br>
            self.setModel()<br>
            self.show()<br>
<br>
            self.ui.splitter.<wbr>setHandleWidth(0)#not working<br>
            self.ui.listView.<wbr>setVerticalScrollBarPolicy(<wbr>QtCore.Qt.ScrollBarAlwaysOn)<br>
                
            self.ui.listView.<wbr>setCornerWidget(self.<wbr>getCornerWidget(self.ui.<wbr>splitter))<br>
 <br>
            self.ui.closePushButton.<wbr>clicked.connect(self.close)<br>
            self.ui.listView.clicked.<wbr>connect(self.showSubFiles)<br>
<br>
      def getCornerWidget(self, splitter):<br>
            self.handle=splitter.handle(1)<br>
            layout=QtGui.QHBoxLayout(self.<wbr>handle)<br>
            layout.setSpacing(0)<br>
            layout.setMargin(0)<br>
<br>
            for i in range(0,2):<br>
                  line = QtGui.QFrame(self.handle)<br>
                  line.setFrameShape(QtGui.<wbr>QFrame.VLine)<br>
                  layout.addWidget(line)<br>
<br>
            return self.handle<br>
<br>
      def showSubFiles(self, index):<br>
            root_path = self.model.fileInfo(index).<wbr>absoluteFilePath()<br>
            self.model1=QtGui.<wbr>QFileSystemModel()<br>
            self.model1.setRootPath(root_<wbr>path)<br>
            self.ui.listView_1.setModel(<wbr>self.model1)<br>
            self.ui.listView_1.<wbr>setRootIndex(self.model1.<wbr>index(root_path))<br>
 <br>
      def setModel(self):<br>
            root_path=os.path.expanduser(&quot;<wbr>~&quot;)<br>
            self.model=QtGui.<wbr>QFileSystemModel()<br>
            self.model.setRootPath(root_<wbr>path)<br>
            self.model.setFilter(QtCore.<wbr>QDir.NoDotAndDotDot | \
QtCore.QDir.Dirs)<br>  self.ui.listView.setModel(<wbr>self.model)<br>
            self.ui.listView.setRootIndex(<wbr>self.model.index(root_path))<br>
class Ui_Form(object):<br>
      def setupUi(self, Form):<br>
            Form.setObjectName(_fromUtf8(&quot;<wbr>Form&quot;))<br>
            Form.resize(602, 365)<br>
            self.verticalLayout = QtGui.QVBoxLayout(Form)<br>
            self.verticalLayout.<wbr>setObjectName(_fromUtf8(&quot;<wbr>verticalLayout&quot;))<br>
  self.splitter = QtGui.QSplitter(Form)<br>
            self.splitter.setOrientation(<wbr>QtCore.Qt.Horizontal)<br>
            self.splitter.setObjectName(_<wbr>fromUtf8(&quot;splitter&quot;))<br>
            self.listView = QtGui.QListView(self.splitter)<br>
            self.listView.setObjectName(_<wbr>fromUtf8(&quot;listView&quot;))<br>
            self.listView_1 = QtGui.QListView(self.splitter)<br>
            self.listView_1.setObjectName(<wbr>_fromUtf8(&quot;listView_1&quot;))<br>
            self.verticalLayout.addWidget(<wbr>self.splitter)<br>
            self.horizontalLayout = QtGui.QHBoxLayout()<br>
            self.horizontalLayout.<wbr>setObjectName(_fromUtf8(&quot;<wbr>horizontalLayout&quot;))<br>
  spacerItem = QtGui.QSpacerItem(40, 20,<br>
QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)<br>
            self.horizontalLayout.addItem(<wbr>spacerItem)<br>
            self.closePushButton = QtGui.QPushButton(Form)<br>
            self.closePushButton.<wbr>setObjectName(_fromUtf8(&quot;<wbr>closePushButton&quot;))<br>
                
            self.horizontalLayout.<wbr>addWidget(self.<wbr>closePushButton)<br>
            self.verticalLayout.addLayout(<wbr>self.horizontalLayout)<br>
            self.verticalLayout.<wbr>setStretch(0, 1)<br>
<br>
            self.retranslateUi(Form)<br>
            QtCore.QMetaObject.<wbr>connectSlotsByName(Form)<br>
<br>
      def retranslateUi(self, Form):<br>
            Form.setWindowTitle(_<wbr>translate(&quot;Form&quot;, &quot;Form&quot;, \
                None))<br>
            self.closePushButton.setText(_<wbr>translate(&quot;Form&quot;, \
&quot;Close&quot;, None))<br> <br>
if __name__ == &quot;__main__&quot;:<br>
      import sys<br>
      app = QtGui.QApplication(sys.argv)<br>
      listView=PopulateList()<br>
      sys.exit(app.exec_())<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: &lt;<a href="https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20170209/cc9a0db7/attachment.html" \
rel="noreferrer" target="_blank">https://www.<wbr>riverbankcomputing.com/<wbr>pipermail/pyqt/attachments/<wbr>20170209/cc9a0db7/attachment.<wbr>html</a>&gt;<br>
                
-------------- next part --------------<br>
A non-text attachment was scrubbed...<br>
Name: image.png<br>
Type: image/png<br>
Size: 28914 bytes<br>
Desc: not available<br>
URL: &lt;<a href="https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20170209/cc9a0db7/attachment.png" \
rel="noreferrer" target="_blank">https://www.<wbr>riverbankcomputing.com/<wbr>pipermai \
l/pyqt/attachments/<wbr>20170209/cc9a0db7/attachment.<wbr>png</a>&gt;<br></blockquote></div><br></div></div></div></div></div>



[Attachment #6 (text/plain)]

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic