PySide2 QComboBox item filtering





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















i have a problem.



I implemented the filtering function using QComboBox in 3dsMax 2016.



And now i want to implement the filtering function in 3dsMax 2018.



So, i changed my code. PySide to PySide2.



The filtering function is work. but typing is not visible.
This is my code.



from PySide2.QtWidgets import QComboBox, QApplication, QCompleter, QLineEdit
from PySide2.QtCore import Qt, QSortFilterProxyModel
from PySide2.QtGui import QStandardItemModel,QStandardItem

from PySide2 import QtWidgets, QtCore, QtGui
import MaxPlus

class SuperDuperText(QtWidgets.QLineEdit):
def focusInEvent(self, event):
MaxPlus.CUI.DisableAccelerators()

def focusOutEvent(self, event):
MaxPlus.CUI.EnableAccelerators()

class ExtendedCombo( QtWidgets.QComboBox ):

def __init__( self, parent = None):
super( ExtendedCombo, self ).__init__( parent )

self.setFocusPolicy( Qt.StrongFocus )
self.setEditable(True)
self.completer = QCompleter( self )

self.completer.setCompletionMode( QCompleter.UnfilteredPopupCompletion )
self.pFilterModel = QSortFilterProxyModel( self )
self.pFilterModel.setFilterCaseSensitivity( Qt.CaseInsensitive )

self.completer.setPopup( self.view() )
self.setCompleter( self.completer )
# SuperDuperText().textEdited[unicode].connect( self.pFilterModel.setFilterFixedString )
# self.lineEdit().textEdited[unicode].connect( self.pFilterModel.setFilterFixedString )
# print self.lineEdit().echoMode() is return Normal

self.lineEdit().textEdited[unicode].connect(
self.pFilterModel.setFilterFixedString)
self.completer.activated.connect(self.setTextIfCompleterIsClicked)

def setModel( self, model ):
super(ExtendedCombo, self).setModel( model )
self.pFilterModel.setSourceModel( model )
self.completer.setModel(self.pFilterModel)

def setModelColumn( self, column ):
self.completer.setCompletionColumn( column )
self.pFilterModel.setFilterKeyColumn( column )
super(ExtendedCombo, self).setModelColumn( column )

def view( self ):
return self.completer.popup()

def index( self ):
return self.currentIndex()

def setTextIfCompleterIsClicked(self, text):
if text:
index = self.findText(text)
self.setCurrentIndex(index)

def focusInEvent(self, event):
MaxPlus.CUI.DisableAccelerators()

def focusOutEvent(self, event):
MaxPlus.CUI.EnableAccelerators()


class SuperDuperUI(QtWidgets.QDialog):
def __init__(self, parent=MaxPlus.GetQMaxMainWindow()):
super(SuperDuperUI, self).__init__(parent)
self.setWindowTitle("Sample UI")
self.initUI()

def initUI(self):
mainLayout = QtWidgets.QVBoxLayout()

maxScriptsDir = MaxPlus.PathManager.GetScriptsDir()
testLabel = QtWidgets.QLabel("Your scripts dir is: " + maxScriptsDir)
mainLayout.addWidget(testLabel)

testBtn = QtWidgets.QPushButton("This does nothing.")
mainLayout.addWidget(testBtn)

testEdit = SuperDuperText()
testEdit.setPlaceholderText("You can type in here if you like...")
mainLayout.addWidget(testEdit)

model = QStandardItemModel()

for i, word in enumerate(['hola', 'adios', 'hello', 'good bye']):
item = QStandardItem(word)
model.setItem(i, 0, item)

combo = ExtendedCombo()
combo.setModel(model)
combo.setModelColumn(0)
mainLayout.addWidget(combo)

self.setLayout(mainLayout)

if __name__ == "__main__":
ui = SuperDuperUI()
ui.show()


I think QCombobox's QLineedit has a focus problem. Maybe......



I tried to redefine qcombobox's qlineedit to SuperDuperText but failed.



Thank you all who read my problem.










share|improve this question































    0















    i have a problem.



    I implemented the filtering function using QComboBox in 3dsMax 2016.



    And now i want to implement the filtering function in 3dsMax 2018.



    So, i changed my code. PySide to PySide2.



    The filtering function is work. but typing is not visible.
    This is my code.



    from PySide2.QtWidgets import QComboBox, QApplication, QCompleter, QLineEdit
    from PySide2.QtCore import Qt, QSortFilterProxyModel
    from PySide2.QtGui import QStandardItemModel,QStandardItem

    from PySide2 import QtWidgets, QtCore, QtGui
    import MaxPlus

    class SuperDuperText(QtWidgets.QLineEdit):
    def focusInEvent(self, event):
    MaxPlus.CUI.DisableAccelerators()

    def focusOutEvent(self, event):
    MaxPlus.CUI.EnableAccelerators()

    class ExtendedCombo( QtWidgets.QComboBox ):

    def __init__( self, parent = None):
    super( ExtendedCombo, self ).__init__( parent )

    self.setFocusPolicy( Qt.StrongFocus )
    self.setEditable(True)
    self.completer = QCompleter( self )

    self.completer.setCompletionMode( QCompleter.UnfilteredPopupCompletion )
    self.pFilterModel = QSortFilterProxyModel( self )
    self.pFilterModel.setFilterCaseSensitivity( Qt.CaseInsensitive )

    self.completer.setPopup( self.view() )
    self.setCompleter( self.completer )
    # SuperDuperText().textEdited[unicode].connect( self.pFilterModel.setFilterFixedString )
    # self.lineEdit().textEdited[unicode].connect( self.pFilterModel.setFilterFixedString )
    # print self.lineEdit().echoMode() is return Normal

    self.lineEdit().textEdited[unicode].connect(
    self.pFilterModel.setFilterFixedString)
    self.completer.activated.connect(self.setTextIfCompleterIsClicked)

    def setModel( self, model ):
    super(ExtendedCombo, self).setModel( model )
    self.pFilterModel.setSourceModel( model )
    self.completer.setModel(self.pFilterModel)

    def setModelColumn( self, column ):
    self.completer.setCompletionColumn( column )
    self.pFilterModel.setFilterKeyColumn( column )
    super(ExtendedCombo, self).setModelColumn( column )

    def view( self ):
    return self.completer.popup()

    def index( self ):
    return self.currentIndex()

    def setTextIfCompleterIsClicked(self, text):
    if text:
    index = self.findText(text)
    self.setCurrentIndex(index)

    def focusInEvent(self, event):
    MaxPlus.CUI.DisableAccelerators()

    def focusOutEvent(self, event):
    MaxPlus.CUI.EnableAccelerators()


    class SuperDuperUI(QtWidgets.QDialog):
    def __init__(self, parent=MaxPlus.GetQMaxMainWindow()):
    super(SuperDuperUI, self).__init__(parent)
    self.setWindowTitle("Sample UI")
    self.initUI()

    def initUI(self):
    mainLayout = QtWidgets.QVBoxLayout()

    maxScriptsDir = MaxPlus.PathManager.GetScriptsDir()
    testLabel = QtWidgets.QLabel("Your scripts dir is: " + maxScriptsDir)
    mainLayout.addWidget(testLabel)

    testBtn = QtWidgets.QPushButton("This does nothing.")
    mainLayout.addWidget(testBtn)

    testEdit = SuperDuperText()
    testEdit.setPlaceholderText("You can type in here if you like...")
    mainLayout.addWidget(testEdit)

    model = QStandardItemModel()

    for i, word in enumerate(['hola', 'adios', 'hello', 'good bye']):
    item = QStandardItem(word)
    model.setItem(i, 0, item)

    combo = ExtendedCombo()
    combo.setModel(model)
    combo.setModelColumn(0)
    mainLayout.addWidget(combo)

    self.setLayout(mainLayout)

    if __name__ == "__main__":
    ui = SuperDuperUI()
    ui.show()


    I think QCombobox's QLineedit has a focus problem. Maybe......



    I tried to redefine qcombobox's qlineedit to SuperDuperText but failed.



    Thank you all who read my problem.










    share|improve this question



























      0












      0








      0








      i have a problem.



      I implemented the filtering function using QComboBox in 3dsMax 2016.



      And now i want to implement the filtering function in 3dsMax 2018.



      So, i changed my code. PySide to PySide2.



      The filtering function is work. but typing is not visible.
      This is my code.



      from PySide2.QtWidgets import QComboBox, QApplication, QCompleter, QLineEdit
      from PySide2.QtCore import Qt, QSortFilterProxyModel
      from PySide2.QtGui import QStandardItemModel,QStandardItem

      from PySide2 import QtWidgets, QtCore, QtGui
      import MaxPlus

      class SuperDuperText(QtWidgets.QLineEdit):
      def focusInEvent(self, event):
      MaxPlus.CUI.DisableAccelerators()

      def focusOutEvent(self, event):
      MaxPlus.CUI.EnableAccelerators()

      class ExtendedCombo( QtWidgets.QComboBox ):

      def __init__( self, parent = None):
      super( ExtendedCombo, self ).__init__( parent )

      self.setFocusPolicy( Qt.StrongFocus )
      self.setEditable(True)
      self.completer = QCompleter( self )

      self.completer.setCompletionMode( QCompleter.UnfilteredPopupCompletion )
      self.pFilterModel = QSortFilterProxyModel( self )
      self.pFilterModel.setFilterCaseSensitivity( Qt.CaseInsensitive )

      self.completer.setPopup( self.view() )
      self.setCompleter( self.completer )
      # SuperDuperText().textEdited[unicode].connect( self.pFilterModel.setFilterFixedString )
      # self.lineEdit().textEdited[unicode].connect( self.pFilterModel.setFilterFixedString )
      # print self.lineEdit().echoMode() is return Normal

      self.lineEdit().textEdited[unicode].connect(
      self.pFilterModel.setFilterFixedString)
      self.completer.activated.connect(self.setTextIfCompleterIsClicked)

      def setModel( self, model ):
      super(ExtendedCombo, self).setModel( model )
      self.pFilterModel.setSourceModel( model )
      self.completer.setModel(self.pFilterModel)

      def setModelColumn( self, column ):
      self.completer.setCompletionColumn( column )
      self.pFilterModel.setFilterKeyColumn( column )
      super(ExtendedCombo, self).setModelColumn( column )

      def view( self ):
      return self.completer.popup()

      def index( self ):
      return self.currentIndex()

      def setTextIfCompleterIsClicked(self, text):
      if text:
      index = self.findText(text)
      self.setCurrentIndex(index)

      def focusInEvent(self, event):
      MaxPlus.CUI.DisableAccelerators()

      def focusOutEvent(self, event):
      MaxPlus.CUI.EnableAccelerators()


      class SuperDuperUI(QtWidgets.QDialog):
      def __init__(self, parent=MaxPlus.GetQMaxMainWindow()):
      super(SuperDuperUI, self).__init__(parent)
      self.setWindowTitle("Sample UI")
      self.initUI()

      def initUI(self):
      mainLayout = QtWidgets.QVBoxLayout()

      maxScriptsDir = MaxPlus.PathManager.GetScriptsDir()
      testLabel = QtWidgets.QLabel("Your scripts dir is: " + maxScriptsDir)
      mainLayout.addWidget(testLabel)

      testBtn = QtWidgets.QPushButton("This does nothing.")
      mainLayout.addWidget(testBtn)

      testEdit = SuperDuperText()
      testEdit.setPlaceholderText("You can type in here if you like...")
      mainLayout.addWidget(testEdit)

      model = QStandardItemModel()

      for i, word in enumerate(['hola', 'adios', 'hello', 'good bye']):
      item = QStandardItem(word)
      model.setItem(i, 0, item)

      combo = ExtendedCombo()
      combo.setModel(model)
      combo.setModelColumn(0)
      mainLayout.addWidget(combo)

      self.setLayout(mainLayout)

      if __name__ == "__main__":
      ui = SuperDuperUI()
      ui.show()


      I think QCombobox's QLineedit has a focus problem. Maybe......



      I tried to redefine qcombobox's qlineedit to SuperDuperText but failed.



      Thank you all who read my problem.










      share|improve this question
















      i have a problem.



      I implemented the filtering function using QComboBox in 3dsMax 2016.



      And now i want to implement the filtering function in 3dsMax 2018.



      So, i changed my code. PySide to PySide2.



      The filtering function is work. but typing is not visible.
      This is my code.



      from PySide2.QtWidgets import QComboBox, QApplication, QCompleter, QLineEdit
      from PySide2.QtCore import Qt, QSortFilterProxyModel
      from PySide2.QtGui import QStandardItemModel,QStandardItem

      from PySide2 import QtWidgets, QtCore, QtGui
      import MaxPlus

      class SuperDuperText(QtWidgets.QLineEdit):
      def focusInEvent(self, event):
      MaxPlus.CUI.DisableAccelerators()

      def focusOutEvent(self, event):
      MaxPlus.CUI.EnableAccelerators()

      class ExtendedCombo( QtWidgets.QComboBox ):

      def __init__( self, parent = None):
      super( ExtendedCombo, self ).__init__( parent )

      self.setFocusPolicy( Qt.StrongFocus )
      self.setEditable(True)
      self.completer = QCompleter( self )

      self.completer.setCompletionMode( QCompleter.UnfilteredPopupCompletion )
      self.pFilterModel = QSortFilterProxyModel( self )
      self.pFilterModel.setFilterCaseSensitivity( Qt.CaseInsensitive )

      self.completer.setPopup( self.view() )
      self.setCompleter( self.completer )
      # SuperDuperText().textEdited[unicode].connect( self.pFilterModel.setFilterFixedString )
      # self.lineEdit().textEdited[unicode].connect( self.pFilterModel.setFilterFixedString )
      # print self.lineEdit().echoMode() is return Normal

      self.lineEdit().textEdited[unicode].connect(
      self.pFilterModel.setFilterFixedString)
      self.completer.activated.connect(self.setTextIfCompleterIsClicked)

      def setModel( self, model ):
      super(ExtendedCombo, self).setModel( model )
      self.pFilterModel.setSourceModel( model )
      self.completer.setModel(self.pFilterModel)

      def setModelColumn( self, column ):
      self.completer.setCompletionColumn( column )
      self.pFilterModel.setFilterKeyColumn( column )
      super(ExtendedCombo, self).setModelColumn( column )

      def view( self ):
      return self.completer.popup()

      def index( self ):
      return self.currentIndex()

      def setTextIfCompleterIsClicked(self, text):
      if text:
      index = self.findText(text)
      self.setCurrentIndex(index)

      def focusInEvent(self, event):
      MaxPlus.CUI.DisableAccelerators()

      def focusOutEvent(self, event):
      MaxPlus.CUI.EnableAccelerators()


      class SuperDuperUI(QtWidgets.QDialog):
      def __init__(self, parent=MaxPlus.GetQMaxMainWindow()):
      super(SuperDuperUI, self).__init__(parent)
      self.setWindowTitle("Sample UI")
      self.initUI()

      def initUI(self):
      mainLayout = QtWidgets.QVBoxLayout()

      maxScriptsDir = MaxPlus.PathManager.GetScriptsDir()
      testLabel = QtWidgets.QLabel("Your scripts dir is: " + maxScriptsDir)
      mainLayout.addWidget(testLabel)

      testBtn = QtWidgets.QPushButton("This does nothing.")
      mainLayout.addWidget(testBtn)

      testEdit = SuperDuperText()
      testEdit.setPlaceholderText("You can type in here if you like...")
      mainLayout.addWidget(testEdit)

      model = QStandardItemModel()

      for i, word in enumerate(['hola', 'adios', 'hello', 'good bye']):
      item = QStandardItem(word)
      model.setItem(i, 0, item)

      combo = ExtendedCombo()
      combo.setModel(model)
      combo.setModelColumn(0)
      mainLayout.addWidget(combo)

      self.setLayout(mainLayout)

      if __name__ == "__main__":
      ui = SuperDuperUI()
      ui.show()


      I think QCombobox's QLineedit has a focus problem. Maybe......



      I tried to redefine qcombobox's qlineedit to SuperDuperText but failed.



      Thank you all who read my problem.







      python qcombobox 3dsmax pyside2






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 17 '18 at 15:23









      eyllanesc

      89.5k113565




      89.5k113565










      asked Nov 17 '18 at 6:49









      엄승탁엄승탁

      103




      103
























          0






          active

          oldest

          votes












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53348937%2fpyside2-qcombobox-item-filtering%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53348937%2fpyside2-qcombobox-item-filtering%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Xamarin.iOS Cant Deploy on Iphone

          Glorious Revolution

          Dulmage-Mendelsohn matrix decomposition in Python