<div dir="ltr"><div class="gmail_default" style="font-family:trebuchet ms,sans-serif">You can save the order to an xml file on disk from which it can read on startup.<br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">

On Thu, Aug 14, 2014 at 6:32 AM, Han Jiang <span dir="ltr"><<a href="mailto:oglops@gmail.com" target="_blank">oglops@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div dir="ltr">i have a treeWidget with itemWidget set on columns, but after dragging the widgets are gone, and the dropping indicator is opaque<br><br>1. How can i make the widget persist after dropping<br>2. How to make dropping indicator transparent ? ( i'm on centos 6.5, the compositing manager is not running)<br>


<br>screenshots are here:<br><br><a href="http://i.stack.imgur.com/d4sFP.png" target="_blank">http://i.stack.imgur.com/d4sFP.png</a><br><a href="http://i.stack.imgur.com/2Oa9A.png" target="_blank">http://i.stack.imgur.com/2Oa9A.png</a><br>

<br>executable example:<br>
<br>    #!/usr/bin/env python2<br>    import os<br>    import sys<br>    import re<br>    <br>    from PyQt4 import QtGui, QtCore<br>    from PyQt4.QtCore import Qt, QString<br><br><br>    class MyTreeWidget(QtGui.QTreeWidget):<br>


        def __init__(self, parent=None):<br>            super(MyTreeWidget, self).__init__(parent)<br>    <br>    class CommandWidget(QtGui.QDialog):<br>    <br>        def __init__(self, parent=None, level=0,script='echo /path/to/script'):<br>


            super(CommandWidget, self).__init__()<br>            self.layout = QtGui.QHBoxLayout(self)<br>    <br>            browseBtn = QtGui.QPushButton(parent)<br>    <br>            browseBtn.setMinimumSize(QtCore.QSize(0, 25))<br>


            # level, path = val<br>    <br>            # levelNum = re.search('(?<=level).+', level).group()<br>            browseBtn.setText('%s : %s' % (level, script))<br>            self._level = int(level)<br>


            self._script = script<br>            browseBtn.setStyleSheet("text-align: left")<br>    <br>            self.layout.addWidget(browseBtn)<br>    <br>            # self.updateGeometry()<br>            self.browseBtn = browseBtn<br>


            # self.layout.addWidget(browseBtn)<br>            self.browseBtn.clicked.connect(self.browseCommandScript)<br>            self.browseBtn.setIconSize(QtCore.QSize(64, 64))<br>    <br>        def browseCommandScript(self):<br>


            script = QtGui.QFileDialog.getOpenFileName(<br>                self, 'Select Script file', '/home/xxx/python', ".py Files (*.py);;Executable Files (*)")<br>            if script:<br>

                self._script = script<br>
                button_label = re.search('[^\\/]*$',script).group()<br>                self.browseBtn.setText(('%s : %s' % (self._level, button_label)))<br>    <br>        @property<br>        def level(self):<br>


            return self._level<br>    <br>        @level.setter<br>        def level(self, value):<br>            self._level = value<br>    <br>        @property<br>        def script(self):<br>            return self._script<br>


    <br>        @script.setter<br>        def script(self, value):<br>            self._script = value<br>    <br>    <br>    class MyLineEdit(QtGui.QWidget):<br>        def __init__(self,value=None,parent=None):<br>            super(MyLineEdit,self).__init__(parent)<br>


            self.layout = QtGui.QHBoxLayout(self)<br>            self.layout.setSpacing(0)<br>            self.layout.setMargin(3)<br>            <br>            self.lineEdit = QtGui.QLineEdit(value)<br>            spacer1 = QtGui.QSpacerItem(20, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)<br>


            spacer2 = QtGui.QSpacerItem(20, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)<br>    <br>            self.lineEdit.setContentsMargins(2,2,2,2)<br>            self.lineEdit.setAlignment(Qt.AlignHCenter)<br>


    <br>            self.layout.addItem(spacer1)<br>            self.layout.addWidget(self.lineEdit)<br>            self.layout.addItem(spacer2)<br>    <br>            self.lineEdit.setMaximumSize(QtCore.QSize(70, 25))<br>


            self.lineEdit.textEdited.connect(self._update_item_widget_data)<br>    <br>        def text(self):<br>            return self.lineEdit.text()<br>    <br>        def setText(self,text):<br>            return self.lineEdit.setText(text)   <br>


    <br>    <br>        def _update_item_widget_data(self,text):<br>            # print 'update',text<br>            self.treeWidgetItem.setData(1,Qt.UserRole,text)<br>    <br>    class TheUI(QtGui.QDialog):<br>    <br>


        def __init__(self, args=None, parent=None):<br>            super(TheUI, self).__init__(parent)<br>            self.layout = QtGui.QVBoxLayout(self)<br>            treeWidget = MyTreeWidget()<br>    <br>            button = QtGui.QPushButton('Add')<br>


            self.layout.addWidget(treeWidget)<br>            self.cssEditTE = QtGui.QPlainTextEdit()<br>    <br>            self.layout.addWidget(button)<br>            self.layout.addWidget(self.cssEditTE)<br>    <br>            self.cssEditTE.textChanged.connect(self._update_css)<br>


    <br>            treeWidget.setHeaderHidden(True)<br>            treeWidget.setRootIsDecorated(False)<br>    <br>            layout = QtGui.QHBoxLayout(self)<br>            rootDecorationCB = QtGui.QCheckBox('RootIsDecorated')<br>


            layout.addWidget(rootDecorationCB)<br>            self.layout.addLayout(layout)<br>            rootDecorationCB.stateChanged.connect(self._update_root_decorated)<br>    <br>            indentationSlider = QtGui.QSlider()<br>


            indentationSlider.setOrientation(Qt.Horizontal)<br>            indentationSlider.setRange(0,100)<br>            indentationSlider.setValue(20)<br>            indentationSlider.valueChanged.connect(self._alter_indentation)<br>


            layout.addWidget(indentationSlider)<br>    <br>    <br>            self.layout.setStretchFactor(treeWidget,1)<br>    <br>            self.treeWidget = treeWidget<br>            self.button = button<br>            self.button.clicked.connect(lambda *x: self.addCmd())<br>


    <br>            HEADERS = ( "script", "chunksize", "mem" )<br>            self.treeWidget.setHeaderLabels(HEADERS)<br>            self.treeWidget.setColumnCount( len(HEADERS) )<br>    <br>


            self.treeWidget.setColumnWidth(0,200)<br>            self.treeWidget.header().show()<br>    <br>            for i in range(len(HEADERS)):<br>                self.treeWidget.headerItem().setTextAlignment(i,Qt.AlignHCenter)<br>


    <br>    <br>            self.treeWidget.setDragDropMode(QtGui.QAbstractItemView.InternalMove)<br>    <br>            self.treeWidget.setIndentation(60)<br>    <br>            self.resize(500,700)<br>    <br>            for i in xrange(2):<br>


                self.addCmd()<br>    <br>            item = self.addCmd()<br>            self.addCmd(parent = item)<br>            self.addCmd(parent = item)<br>            item = self.addCmd()<br>    <br>            item=self.addCmd(parent = item)<br>


            self.addCmd(parent = item)<br>            self.addCmd()<br>    <br>            self.treeWidget.setColumnWidth(0,200)<br>    <br>        def addCmd(self, level=0, script='echo /path/to/script',parent=None):<br>


            'add a level to tree widget'<br>    <br>            root = self.treeWidget.invisibleRootItem()<br>    <br>            if parent is None:<br>                parent = root<br>            item = QtGui.QTreeWidgetItem(parent)<br>


            # item = QtGui.QTreeWidgetItem(self.treeWidget.invisibleRootItem())<br>            item.setFlags(item.flags() | QtCore.Qt.ItemIsDropEnabled)<br>    <br>            existingLevels = self.treeWidget.topLevelItemCount()<br>


            # level, path = val<br>            # level = level % existingLevels<br>    <br>            cmdWidget = CommandWidget(self.treeWidget, existingLevels, script)<br>            self.treeWidget.setItemWidget(item, 0, cmdWidget)<br>


    <br>            line_edit_1 = MyLineEdit('1')<br>            line_edit_2 = MyLineEdit('200')<br>    <br>            self.treeWidget.setItemWidget(item, 1, line_edit_1)<br>            self.treeWidget.setItemWidget(item, 2, line_edit_2)<br>


    <br>            item.setExpanded(True)<br>            return item<br>    <br>        def _update_css(self):<br>            self.treeWidget.setStyleSheet(self.cssEditTE.toPlainText())<br>    <br>        def _update_root_decorated(self,state):<br>


            if state == Qt.Checked:<br>                self.treeWidget.setRootIsDecorated(True)<br>            else:<br>                self.treeWidget.setRootIsDecorated(False)<br>            self.treeWidget.updateGeometries()<br>


    <br>        def _alter_indentation(self,value):<br>            print value<br>            self.treeWidget.setIndentation(value)<br>            self.treeWidget.updateGeometries()<br>    <br>    <br>    <br>    if __name__ == '__main__':<br>


        app = QtGui.QApplication(sys.argv)<br>        gui = TheUI()<br>        gui.show()<br>        app.exec_()<br><br><br></div>
<br>_______________________________________________<br>
PyQt mailing list    <a href="mailto:PyQt@riverbankcomputing.com">PyQt@riverbankcomputing.com</a><br>
<a href="http://www.riverbankcomputing.com/mailman/listinfo/pyqt" target="_blank">http://www.riverbankcomputing.com/mailman/listinfo/pyqt</a><br></blockquote></div><br><br clear="all"><br>-- <br><b></b>
    <p><a href="http://feeds.feedburner.com/SanLuthraBlog" target="_blank"><img src="http://feeds.feedburner.com/SanLuthraBlog.gif?w=1&c=1&bb=zCxf" alt="San's personal blog"></a></p>

    
    <form action="http://fb/a/headlineanimator/install" method="get" accept-charset="utf-8" target="_blank" onsubmit="return window.confirm("You are submitting information to an external page.\nAre you sure?");">


      <p style="background-image:url('/fb/lib/images/icons/chameleon_red/add.gif')">
        <b><br></b></p></form>
</div>