How to implement a table with multiple colums filter and QPushButton on each row? - qt

I'm stuck. With QTableView + QStandartItemModel + QSortFilterProxyModel I can only add 1 QLineEdit for 1 specific column line_edit.textChanged.connect(filter_model.setFilterRegExp). Moreover I can't figure out how to add widget item to QTableView but only to QTableWidget (which i can't use because of filter?). I may give up the idea of adding widget and just make my whole row open another dialog on double click.But still I don't understand how to filter multiple columns at the same time. Thanks in advance

Moreover I can't figure out how to add widget item to QTableView
You need use QtGui.QItemDelegate for such thing. Have a look at this nice code snippet (not mine). And please read Qt manual about QItemDelegate and Model View Delegate pattern.

Related

How to add column before treecolumn in Qt qtreeview

I want to add a column before the tree column.
A similar thing is visible in the picture.
But I can't find any examples of that.
To achieve this. It is necessary to swap columns, as shown in the example. It works the same way on all Qt languages that have QTreeView.
QTreeView *view;
view->setModel(model);
view->header()->swapSections(0, 1);

What is the best way to implement this using Qt

I'm totally new to Qt, so I'd be glad to have a wide answer.
Here I drew up some model:
We have a kind of table that contains:
an integer value with a spinbox.
a cell with three(not specifically) grouped radio buttons
Editbox
A button that interacts with this particular editbox.
Also we have 2 buttons to add and remove items from the table.
I did some google search and found out that it can be done via QTableView.
Is there any way to put such complex structures into a cell? Must it be a separate class inherited from QTableView?
If you're going to have up to a hundred or maybe a few hundreds of elements in the table, then use QTableWidget.
If you're going to have too many elements (about thousands), then go for QTableView, and learn model-view programming.
The reason why I recommend QTableWidget is because you're a beginner. All you have to do there is create a widget, and use setCellWidget() and you're done.
If you have thousands of rows, then you're gonna have to draw the widgets yourself using QStyledItemDelegate, which will paint the widgets inside your QTableView. This is a very painful thing to do, but there's no way around it. The reasons you can find here.
I see at least three options to implement that in Qt:
Use a QtableView or QTableWidget and insert some custom controls in it. See comments made be other persons to your post
Use a QGridLayout and fill it with your controls by line and column
Make your own QWidget to store and manage the line elements (the spinbox, edit field, radio button) using a QHBoxLayout. You can design this in QtCreator, it can have it's own .ui. This could make it easy to handle the interaction between each QWidget of a line (directly handled by your QWidget class). Later, you can put an instance of it for every line you need in a QVBoxLayout.
Personnaly, I would go with the last option, but it may not work smartly if the controls of each line have different content/size (see comments), then first options should be prefered.

Focusing on last data entry on Qtreewidget

I am trying to use Qtreewidget as listview (like in C#) to display some data. As seen on the image below, while new datas displayed during the runtime, the widget doesn't focus on the last entry.That is what I want but couldn't find a method to make it focus on the last entry. In other words, I want it to be scrolled down to the last entry. Is there any way to do it or do I have to use something another to handle this ?
Thanks in advance.
Maybe this code will helps you:
QTreeWidget *mytree = new QTreeWidget(this);
...
mytree->scrollToBottom();

How to display drop-down in column of QTableView and filter based on drop-down

I am newbie to Qt. I have to display a chunk of data in a QTableView and filter it column wise. For this I have used QSortFilterProxyModel, but as per requirement each column of the QTableView should have a drop-down list which shows unique values in that column. On selection of any of these values in the drop-down, only the rows having that particular value in the column should be displayed in the QTableView (Like you can do in Excel).
How would I implement this?
I had the same issue a week ago
I found a tutorial explaining how to do it. see link below
http://programmingexamples.net/wiki/Qt/Delegates/ComboBoxDelegate
Now my problem is how to retrieve the value of a specific combobox.
I think it is such a complex things to do in C++ and Qt display a combobox into a tableView.
For being a web developer at first I can tell that web language are better suited to do thoses kind of things.
But still some time performance matter and I tried to do it in C++ with Qt but it is not as easy as it seems to be in Web language.
This is very general question, and if I try to explain it all it will take pages, so it's better if you read the Qt model/view architecture documentation.
You can create your own class inherited from QTableView to create your customized table view. You have to use delegates for drop down functions and all. so read the QItemDelegate class documentation and documentation on subclassing delegates as well.
If you want to display it always and not just when editing, I would suggest setting a widget for the specific column like described in this thread: Qt - QTableView - Clickable button in table row

QListView how to add column?

How can I add columns to QListView control. Found a method addColumn while seardhing, but in my Qt Creator 1.2.1 based on Qt 4.5.2(32 bit) QListView doesn't have such method at all !!!
So how would I add columns ?
Say I have 3 columns then what is the code to add a row ?
You can use QTableView for this purpose. But if you need QListView look & feel, you can use QTableView borderless using Qt Stylesheet. Also you may want to add an icon. You can add icons to your QTableView by setting icon data to Qt::DecorationRole.
You cannot add a column, cause list views are designed to view simple lists. You need QTable[View/Widget].
QListWidget is a single column only. Use QTreeWidget/View for multiple columns.
As the start point you could watch how works QTableView class here: http://qt.nokia.com/doc/4.2/sql-tablemodel.html and do the similar things with QListView. So, you can't just emit addColumn() for QListView class, first you need to create model and then do listView->setModel(model).

Resources