Connecting QLineEdit to SortFilterProxyModel

72 views
Skip to first unread message

Bay

unread,
Oct 26, 2013, 2:04:16 PM10/26/13
to python_in...@googlegroups.com
Hi all, 
          sorry to fill the board again. At the moment I'm trying to implement a filter for my qtreeview. So far I've managed to implement a sorter using the QSortFilterProxyModel and I'm able to sort my list by clicking the headers in my model. However, I've not been successful connecting my QLineEdit to the filter proxy so I'm wondering if I've missed a step. This is the code for my GUI. Any assistance is much appreciated. 

Thank you
Gann Boon Bay

class Selector( QtGui.QMainWindow ):


    def __init__( self, parent=mayaMainWindow() ):

        super( Selector, self ).__init__( parent )

        self.setWindowTitle("SelectionUI")
        self.resize(250,600)

        self.create_layout() # Creating GUI

        #Create Proxy Model
        self._proxyModel=QtGui.QSortFilterProxyModel()

        self._model=listbuild.SceneGraphModel()

        self._proxyModel.setSourceModel(self._model)

        self._proxyModel.setDynamicSortFilter(True)

        self._proxyModel.setFilterCaseSensitivity(QtCore.Qt.CaseInsensitive)

        self.tree.setModel(self._proxyModel)
        #End Proxy Model

        self.tree.setSortingEnabled(True)

        self.selModel = self.tree.selectionModel() # Selection Model

        self.selModel.currentChanged.connect(self.selectInScene)


        self.create_connections() #Create Connections
        self.show()


    def create_layout(self):
        #Creating GUI

        self.main_widget = QtGui.QWidget()
        self.setCentralWidget(self.main_widget)
        self.main_layout = QtGui.QVBoxLayout(self.main_widget)

        self.main_layout.setContentsMargins(10,10,10,10)

        self.filterLineEdit = QtGui.QLineEdit()#Search LineEdit

        self.tree=QtGui.QTreeView()
        self.tree.setAlternatingRowColors(True)
        self.tree.setSizePolicy(QtGui.QSizePolicy.Preferred,
                                QtGui.QSizePolicy.Expanding)

        self.tree.setSelectionBehavior( QtGui.QAbstractItemView.SelectRows )
        self.tree.setSelectionMode( QtGui.QTreeView.ExtendedSelection)

        self.main_layout.addWidget(self.filterLineEdit)
        self.main_layout.addWidget(self.tree)

        label=QtGui.QLabel("SelectionButton")
        self.main_layout.addWidget(label)

        button_layout = QtGui.QHBoxLayout()

        self.main_layout.addLayout(button_layout)

        self.selModel = self.tree.selectionModel()

        #buttons

        self.add_button = QtGui.QPushButton("Add")
        self.remove_button = QtGui.QPushButton("Remove")
        self.quit_button = QtGui.QPushButton("Quit")

        button_layout.addWidget(self.add_button)
        button_layout.addWidget(self.remove_button)
        button_layout.addWidget(self.quit_button)



    def create_connections(self):

        QtCore.QObject.connect(self.filterLineEdit, QtCore.SIGNAL('textChanged(QString'),self._proxyModel.setFilterRegExp)

        # Connect the buttons
        self.connect(self.add_button, QtCore.SIGNAL("clicked()"), self.add_Object)
        self.connect(self.remove_button, QtCore.SIGNAL("clicked()"), self.remove_Object)
        self.connect(self.quit_button, QtCore.SIGNAL("clicked()"), self.close_Dialog)

        self.selModel.selectionChanged.connect(self.selectInScene)

Justin Israel

unread,
Oct 26, 2013, 3:21:35 PM10/26/13
to python_in...@googlegroups.com

Could it be that your are missing a closing character on your signal slot?

QtCore.QObject.connect(self.filterLineEdit, QtCore.SIGNAL('textChanged( QString'),self._proxyModel.setFilterRegExp)

Here
'textChanged( QString'

You are using new style signal slots in some places and old style in others. Why not just use them all the time and avoid the potential typos?

self.textChanged.connect(...)

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/7d9656e8-76ef-4f6b-8694-bb7abdfe9381%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Bay

unread,
Oct 26, 2013, 4:18:06 PM10/26/13
to python_in...@googlegroups.com
And....I feel like an absolute idiot for posting....

Hi Justin, 
              thanks again. Right now I'm mostly following the pyqt tutorial from Yasin Uludag which is about 2 and a half years old because it's the closest thing to what I want to achieve. That's probably why I'm using so much old commands and only adding new ones when I want to get a functionality that was not in the tutorial. 

Justin Israel

unread,
Oct 26, 2013, 6:19:57 PM10/26/13
to python_in...@googlegroups.com

Actually it was pretty common for me to mess up the old style signals too, by typing something wrong. So, no worries :-)

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages