Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Filter QTableView rows with QSortFilterProxyModel and ComboBox
Forum Updated to NodeBB v4.3 + New Features

Filter QTableView rows with QSortFilterProxyModel and ComboBox

Scheduled Pinned Locked Moved Unsolved Qt for Python
4 Posts 2 Posters 3.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hachbani
    wrote on last edited by
    #1

    Hello,

    Its been two days that I'm trying to implement this thing, but can't figure it out.

    I'm using Pyside2, python 3.8, Qt 5.

    • I have a QTableView with a QAbstractTableModel to it. I have a Combobox (ComboBoxColumns) that lists all my columns headers, and a second Combobox (ComboBoxValues) that lists all the distinct values in the column that is selected in the ComboBoxColumns. My two ComboBoxs are connected to two different QStringListModel.

    • What I want is to only keep the rows where the Value(row, ComboboxColumns.currentIndex) == ComboBoxValues.currentIndex.

    I'm trying to implement a ProxyModel class from QSortFilterProxyModel, even after two days of reading documentations and other threads on StackOverflow, Qt Forum. I still have no clue on how to do it.

    If someone can guide me through this, at least just to put me on the right rails, I'd be thankful.

    Thanks;

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Wouldn't it be simpler to set the same model on your combox and set the appropriate model column based on your ComboBoxColumns selection ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • H Offline
        H Offline
        hachbani
        wrote on last edited by
        #3

        For the comboboxs, I have them set up just right, I need to implement a proxy model and connect it to COmboboxColumns.currentIndexchanged signal. I dont know how to override the acceptRows function in the proxy model class.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          There's an example in the QSortFilterProxyModel documentation.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved