Need a GridView for Qt without QML - qt

Is there a GridView implementation for native Qt (not for QML)? I need to read some data from model and put them into GridView.
GridView in QML support dynamic rows/columns, it's friendly to the users when resizing. Or, I have to implement it with QWidget and QGridLayout?

In my experience you have several possibilities:
As you said, use QGridLayout to display your custom data
QTableView works out of the box with Qt model classes, you can pretty much customize it easily to include widgets and other data as you wish.
Use QGraphicsView/QGraphicsScene to draw a grid, basically QML is built on top of QGraphicsView... it shouldn't be too hard.

QTableView or QTableWidget should be the starting points.

There is commercial data grid for Qt/C++ here http://www.devmachines.com/qtitandatagrid-overview.html We use it without any issues.

Related

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.

Use Model/View on a QListWidget

Yes, you are right. We have QListView already, it is prefect when we are trying to display simple list with Model/View.
But, QListView has lots of problem when we need to display complex list with rich text and widgets. Just think about a timeline-listview for Facebook or Twitter.
Sure, we can implement our own delegate for rich text or images, but ListView can print static item only. So, there isn't a way to show clickable hyperlink (you can calculate position of the mouse and hyperlink, but it is a really drity work) or load asynchronous images.
Well, QListWidget seems our solution. We can put widgets into it. But. we will lost our Model/View/Delegate architecture, that is terrible!
Now, my solution is writing my listview in QML. Other widget are still native Qt widget. (I don't like a non-native pure QML user interface.)
QML is really flexiable when doing that kind of work. Then export my model, finally put a viewer into my QMainWindow. But coding in two programming languages and trying to communicate with other native widget is really difficult.
So, is there a way to use Qt's Model/View architecture with QListWidget? Or I have to implement them by myself?
QListWidget does use Qt's MVC, as it derives from QListView and...
QListWidget uses an internal model to manage each QListWidgetItem in
the list.
Just use QListWidget::model () const to access the model.

qt equivalent for docking control to it's container in winforms

I'm trying out qt creator lately and i hate reading hours of docs and tutorials just for doing simple tasks.
So, in winforms i can drag & drop a control from toolbox and set the dock property so it automatically maximizes itself to it's container's size.
What is the equivalent of this behaviour in qt?
I googled this and found it strange that nobody wondered the same before.
There are differences between the concepts of WinForms and Qt. You need to study the concept of layouts. Take a look at the relevant part of the documentation of Qt Designer: Using Layouts in Qt Designer
Before a form can be used, the objects on the form need to be placed
into layouts. This ensures that the objects will be displayed properly
when the form is previewed or used in an application. Placing objects
in a layout also ensures that they will be resized correctly when the
form is resized.
Qt uses layouts. Add QHBoxLayout or QVBoxLayout to the parent widget.

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

Customize List View Item in Nokia Qt App

I am writing a simple file browser app with Nokia Qt4.7 on Symbian^3 platform. I can display the directory/file list in the listview widget using QFileSystemModel. But I want to customize the list view item. And I am using QItemDelegate to do the trick overriding sizHint and paint functions. I want to display a checkbox in the end of every item (ListMode) or in the right down corder of the icon(IconMode). How can I do it?
Thanks.
I'd suggest you to reimplement QItemDelegate::paint function and use QStylePainter and use QStylePainter::drawControl to render checkbox element. Depending on the mode you can vary your painting.
You can also do this using QML . Styling rows is much easier in QML.
To be more specific your Model will still be c++ . Only the list can be in QML.

Resources