QCompleter for QTableWidgetItem to autocompelte - c++

I have a QTableWidget has a QTableWidgetItem that contains a code a user will supply. This code is known to the database and is suppose to autosuggest to the user as he types. How do I connect a QCompleter to a QTableWidgetItem. I know how to do it with a QLineEdit, but I have not found an example with a QTableWidgetItem.

I managed to come up with a solution, though not exactly by using a QTableWidgetItem, basically I placed a QLineEdit in the cell instead and attached the QCompleter to that.

Not sure how far this will get you, but take a look at this
http://docs.huihoo.com/qt/4.4/demos-spreadsheet-main-cpp.html
Search for completer in the code.

Related

Qt: Showing a list of Users/Clients and when clicked, showing profile

in my Qt project, I have a list of Clients. I have to show their name and workplace. Proposed ui looks something like this:
Facts:
Number of client is variable, so the number of dotted rectangular box in the image is not fixed
stylesheet of Name and Some info is different
When clicked on the box (a cell in the table), we have to show something like user/client profile for that client.
What we tried:
We tried using tablewidget, but can't handle the function of showing profile based on click on table cell.
We need suggestion how we can implement that.
I don't think using tablewidget is the best idea here (But it could be, depending on your needs and if you pay attention to future evolution).
I think a good solution could be to create a custom widget MyCell which would be a cell (Pretty sure you guess it thanks to the name ;) !)
In this MyCell class you can add your information (probably QLineEdit ? No really matter in our example).
Then you have to implement QWidget::mousePressEvent(QMouseEvent *event) function, and do what you want in it (Open a new Dialog in your case).
You can have a class MyTable with N MyCell put in a QGridLayout.

QTextEdit auto text finisher

Is there any QT class for creation text finisher (If I type "hel", it will automatically finished word with "lo")? Sorry for bad terminology, I don't know how to describe it better.
There is QCompleter but that works an QLineEdit and QComboBox by default only. I never used it but I suppose it should be possible to attach it to a customized QTextEdit too.
Maybe google with QCompleter and QTextEdit as keywords.

Add QSqlQueryModel or index value to QListWidget

Is there a way to add my QSqlQueryModel to a QListWidget? If not is there a way to add the database row id to a QListWidgetItem?
I cant figure this out from the documentation on QListWidget. I can add items to the list but can only think to use the row number of the item as the hidden index which wont work if index numbers are out of order.
OK, here is the deal:
The QListWidget is part of the older Qt3 data widget set.
The widget you actually want is part of the newer "interview" Qt MVC framework. It is called QListView.
It can be a bit confusing.
In general: A "QxxxxView" widget can be bound to a "QxxxxModel" object, such as the QSqlQueryModel you asked about.
See:
http://qt-project.org/doc/qt-4.8/qlistview.html
And:
http://qt-project.org/doc/qt-4.8/model-view-programming.html
Lot's of good examples. For instance:
http://qt-project.org/doc/qt-4.8/sql-querymodel.html
Good luck.
:)

SpinBoxDelegate and QItemDelegate

I work on project It's like SpinBoxDelegate in Qt sample project but I must customize It, I mean having different widget(textbox) in second and third column of table view instead of spainBox.What do you suggest?
Try instead tableView.setItemDelegate(&delegate); from the example something like QTableView::setItemDelegateForColumn().
Plus have a look at this one tutor.
If you can use a QTableWidget instead of a QTableView you can use QTableWidget.setCellWidget() to put another widget inside a cell. For instance, you could put your own QLineEdit or QSpinBox in the cell.
Unfortunately, if you have to display too many of these it will cause performance issues.

Keep the selection after filtering a QTableView with a QSortFilterProxyModel

I created a QTableView linked to a QSortFilterProxyModel linked to another model.
Under the QTableView (in the GUI) there is a QLineEdit used for "searching" an element in the view.
My idea is to write in the QLineEdit what I'm looking for and let the view show only the matched elements. After filtering, I want to select the concerned item and then clean the QLineEdit for returning at the complete view.
Everything works but the selected item that will be filtered will also lose the selection because of the invalidation.
How can I solve this problem?
Why don't you remember the selected rows before the filtering and then just restore it when you're done with filtering.
You could use the QItemSelectionModel directly I'd imagine.
Use QItemSelectionModel::selectedRows() before filtering and select rows after filtering using QItemSelectionModel::select().
I know this thread is very old, but I thought I'd leave the comment for anybody else facing a similar problem.
From what you wrote it looks like the problem is in the QTableView loosing selection when you're cleaning your QLineEdit content. If you're starting your 'search' routine in the line edit's editingFinished() or textChanged() signals you can disconnect from them before changing the QLineEdit and then reconnect back again. Or use a boolean flag and don't change filtering when it's on. It would be much easier to answer your question if you would post up a simplified version of your code with the problem you're having.