I have a QSqlTableModel that has 3 columns that I want to filter. Sometimes I want to filter on one of the columns, sometimes on all 3 columns and then only on two.
I cannot show any code as i have not written any. I am thinking on using a string, which is plug on the model->setFilter() function, that depending on the button pressed adds or take out parts of this string to form the filter phrase. Is there something that I missed on the description of the QSqlTableModel that would do this more efficiently?
Related
I currently have a search button and I would like to search a specific column of my model.Thus I just want the matching rows to be displayed in my tableview.
I have attached a QSortFilterProxyModel* object as a source to the table view and have set a QStandardItemModel* as its source. Then with my search button I made the following connection
QObject::connect(ui.lineEditSearch,SIGNAL(textChanged(QString)),proxyModelFilter,SLOT(setFilterFixedString(QString)));
Now I was under the impression that upon typing the relevant rows will be returned. Then I realized that I havent specified as to which columns I want the filter proxy model to search.
I understand that I could implement a class that inherits from QSortFilterProxyModel and re implement its filterAcceptsRow. I wanted to know if there was a way for me to avoid creating a class that inherits from QSortFilterProxyModel and simply use the QSortFilterProxyModel class only to tell which columns to search on when the Slot setFilterFixedString is called ?
The column to filter by can be set via QSortFilterProxyModel::filterKeyColumn.
It allows to specify a single column, or all of them (-1, the default).
Alternatively, one can define a custom filter role returning a concatenation of all string to search for, and set it via setFilterRole().
Aloha
I have a QTableWidget with two columns that are currently using a ComboboxDelegate (my subclass of QItemDelegate) to present options to the user. I'd like the choice in the first column to effect the options available in the second, for the current row only.
E.g have a list of cars in the first column, and in the second a list of colours which are available for that car. Other rows to have different cars selected and thus different colour choices available.
From what I can see, I can only set an item delegate per row or column, so I can't see how to change the options in the second column's delegate without affecting all the other rows.
Is this possible? I'd really like to avoid going to a full view/model separation as I have quite a bit of code looking at this QTableWidget already (and I'm under time pressure)
Well for those interested; I went back to my pre-delegate approach, which was to use QTableWidget::setItemWidget() to provide a combobox widget for each cell.
I subclassed qcombobox to take a reference to the table, and connected the combobox CurrentIndexChanged with a slot to update the table data.
(setting a widget in a cell does not affect the tablewidget data unless you do this).
Using a full combobox like this is more expensive than an itemdelegate, but my tables are very small so I can get away with it. The rendering of the combobox is not as nice as the delegate (the combobox is visible all the time instead of only during editing in the delegate's case), but with time I'm sure I can improve on this.
I have a Kendo Grid which represents a many-to-many join table (between Parts and Templates). I want to look up the PartID with a combo box that lists parts by PartNumber instead of by PartID.
A rough image of what I want to acheive.
The question is not clarified. Basically how to deal with foreign key columns is covered in this demo. Also this one is pretty similar.
This question is to understand how to update any row programatically.
Details.
I have a listcrtl, that accepts the data from either from a file or from the edit controls in the dialog. When the items are added I will know its position, that I added, so I can change its subitem texts. I have even implemented the sort functionality in the list, so now the position keeps changing. I have an identifier column for each row, so that I can recognize the row.
Now, from an out side event, if I have to change an other columns value of an ID that I know , I have to first find the position of the item by comparing the id column, then with that position, I have set the subitemtext.
This works fine except that it takes time to find the row first then it need to update the column.
Now, in order to get the row directly, I need some help.
I have gone through
http://msdn.microsoft.com/en-us/library/windows/desktop/hh298346(v=vs.85).aspx
But this does not use MFC. Please help me achieving this.
If you have many items you should consider switching to Virtual Lists. It is the fastest way to access the data. If you do not want to invest time to this, then the easiest way for you will be the following:
When you populate the CListCtrl store the ID of each item in the item data using the SetItemData() method. The ID will always be associated with the item, even after re-sorting.
When you need to locate the required item, just scan all items, but do not use GetItemText(). Use GetItemData() instead. This will be faster
I have a question. I have a GtkListStore and a GtkTreeView, and I want to sort the GtkListStore and update the result to the GtkTreeView when the user clicks on a certain column of the GtkTreeView. I am assuming that the columns are clickable, and cannot be re-ordered, so the numerical order of the columns can be used to set the sorting column's index. But I cannot seem to find which signal gets emitted when the user clicks on the header of a particular column. I have gone through the GTKMM documentation time and again, but it does not seem to be mentioned!
Use Gtk::TreeView::get_column(<column-no>) to get a particular column and attach to its "clicked" signal using Gtk::TreeViewColumn::signal_clicked():
Gtk::TreeViewColumn* col = myview.get_column(SOME_COLUMN_NUMBER);
col->signal_clicked().connect(sigc::mem_fun(*this,&some_method));
That's not how you're supposed to do it.
There can be several views hooked up to the same model; sorting is not something you do to the model, it's something you do to the view.
See the GtkTreeSortable interface (and its GtkTreeModelSort implementation).