SpinBoxDelegate and QItemDelegate - c++

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.

Related

Is there a nice way to map a QStandardItemModel to many QLineEdits

I have a single value that needs to appear on several parts of my UI.
Where I have a list of values that is duplicated - for instance QComboboxes, I create a single QStandardItemModel and set that model on the combos.
I'd like to do something similar for this single value. Great, I thought, I'll use QDataWidgetMapper, but it turns out that QDataWidgetMapper doesn't allow one to many mappings, i.e. I can only map one widget to each column in my table. I'd like to map many.
I can think of a few roll-my-own ways around this but if there's an easy way to do it that is built in, I'd appreciate hearing it. I'm on Qt 4.7 fwiw.
You could create a QDataWidgetMapper for each widget.
Alternatively, make one widget be the 'master value' and connect its valueChanged() signal (or whatever you want to call it) to the corresponding setValue() slot of all the 'slave' widgets.

Creating a List of QPushButtons

I'd like to create a list of QPushButtons that are added and removed at runtime. I figure that an item view widget would accomplish this (QListWidget). The reason for wanting to use an item view instead of a layout is that I would like to scroll through a list of buttons instead of just trying make them all fit. However, I don't see too many examples of QListWidgets being used to store a QPushButtons.
I'd like some tips, pointers, or examples.
I think you should not use QListWidget in this case. Create a widget with a layout and all your buttons. Then put in QScrollArea.
You can add widgets to QListWidget using its setIndexWidget function.

QTreeView: How to put multiple widgets in one cell?

I'd like to put multiple widgets in one cell of a QTreeView. QTreeView already does this with check boxes (e.g if you set ItemIsUserCheckable and ItemIsEditable). For example, how would I show a small tool button next to a line edit, instead of the check box next to the line edit?
I've gone through the whole deal of subclassing Qtreeview, implementing a custom ItemDelegate, and overriding paint( ) and createEditor( ). And that works if I only need to render simple things, like a single line edit, single button, etc. However, I cannot get it to work for nested components.
I tried to create a QHBoxLayout, add a QLineEdit and a QToolBarButton to it, add the layout to a new QWidget, and return the whole thing from createEditor( ). However, nothing shows up.
Can anybody provide a simple example?
Thanks!

customlist in Qt

I want to create a Custom List which will contain not only a single line text but a combination of text, images buttons, progressbars. Is there any way to do this? I am unable to create that.
Please help me.
You can try to use QTableWidget where you can display a widget in a cell.
In your case you can do this:
Create a custom widget with buttons, progress bar, etc.
Implement a QTableView with only one column
Insert an instantiate custom widget in each row you are using
This should do what you want to achieve

Show a download list with qt4

What is the best way to show a list of downloads using QT4?
1 QListWidget
2 QTreeWidget
3 QTableWidget
Thanks
It depends on how much functionality you want. If you just want to simply list the filenames, use a QListWidget. If you want to list other things like progress, filesize, etc. then you may want to use a QTableWidget. If you want to be able to group downloads under different categories, you can use the QTreeWidget, which will also allow for multiple table cells per row like the QTableWidget.
If you want something fancier like the firefox downloader, you may have to create an item delegate to handle the drawing yourself.
Use the model-view-controller widgets.
QListView
QTableView
QTreeView