Results 1 to 3 of 3

Thread: How to filter items of a combobox in tableview and QSqlRelationalTableModel?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,328
    Thanks
    317
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to filter items of a combobox in tableview and QSqlRelationalTableModel?

    i know this forum is for c++ but as it is related to Qt
    The forum is for any Qt-related programming question. Because of Qt's history, most of the Q&A is about C++, but Python + Qt is becoming more popular so questions about PyQt (and other bindings) are welcome.

    I am neither a Python nor SQL expert, so I hope someone can give you an answer.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  2. #2
    Join Date
    Jun 2021
    Posts
    2
    Qt products
    Platforms
    Unix/X11

    Default Re: How to filter items of a combobox in tableview and QSqlRelationalTableModel?

    Thank you d_stranz

    I found a way. everything work as I expected except one thing. I did this by re implementing QSqlRelationalDelegate as this:
    Qt Code:
    1. class mydelegate(QSqlRelationalDelegate):
    2. def __init__(self, parent=None):
    3. super().__init__()
    4. self.tab=parent
    5.  
    6. def setEditorData(self,editor,index):
    7. if index.column()==2:
    8. test= ((self.tab.selectionModel().currentIndex().siblingAtColumn(1).data()))
    9. editor.model().setFilter("type_IDs like '"+test+"%'")
    10. return super().setEditorData(editor,index)
    To copy to clipboard, switch view to plain text mode 


    the only problem remains is changing an item in column 1 doesn't changes items in column 2 automatically and I have to modify second Column manually else it remains wrong option.
    for example if column 1 be "IC" and Column 2 be "Timer" and then i change column 1 to "Transistor" column 2 remains "Timer" unless I edit that too.

    how to solve this?

Similar Threads

  1. Replies: 0
    Last Post: 14th August 2018, 11:57
  2. Replies: 0
    Last Post: 31st October 2010, 21:55
  3. Combobox entries filter as I type
    By yazwas in forum Qt Programming
    Replies: 3
    Last Post: 8th August 2009, 14:04
  4. QSqlRelationalTableModel and comboBox
    By musti in forum Newbie
    Replies: 9
    Last Post: 14th October 2007, 09:43
  5. Realtime TableView filter with (lineEdit)
    By xgoan in forum Qt Programming
    Replies: 2
    Last Post: 21st December 2006, 15:17

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.