Creating a List of QPushButtons - c++

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.

Related

act on all children at once on pyqt widget

is it possible to somehow obtain possibility to control all the children of a certain Qt.Widget?
For example in a Qgroupbox I have many QtextEdits that I want to clear (clear contents, not delete) at once?
I don't think this is possible. However, you can easily find the child widgets of your groupbox and iterate over them. I think that is your best option.
Something like this:
[textEditor.clear() for textEditor in myGroupBox.findChildren(QtGui.QTextEdit)]
You can add a name parameter to findChildren if you want to filter further by the objectName property of your QTextEdits.

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!

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.

create a scrollbar in a submenu qt?

I have a map application and a submenu which has dynamically added objects (i.e. points on a map) added to the submenu, depending on the layer that is loaded. I have the ability to hide each individual objects (i.e. a point) by clicking on the corresponding submenu item. Is there any way to organize the submenu? When there are a lot of points (i.e. 100) the entire submenu takes up the screen. Can I add a scrollbar to a submenu? I looked in the documentation, but couldn't find anything that support this feature.
From this bug report I was able to find out that you could do the following:
submenu->setStyleSheet("QMenu { menu-scrollable: 1; }");
Works like a charm.
There is no such possibility as far as I know.
Maybe you shouldn't use a sub menu for this but prefer a menu entry that show a Point manager GUI of your own which would have a QListWidget displaying all your points items.
I'm aware that this solution will break a (big?) part of your code but I don't see anything else.
I think you may be able to get the effect you want by creating and using your own QStyle subclass (via QApplication::setStyle()), and overriding the styleHint virtual method to return 1 when the StyleHint parameter passed in is SH_Menu_Scrollable. At least, that works for me when I create large QMenu objects and show them as popup menus.... It may also work for QMenus attached to the menu bar, but I havent tried that.
Whilst it is possible by subclassing the QMenu class to create a custom widget and going from there you're better off looking at a better way to display that information. You'll save yourself time and it'll be much easier for your users to not have to scroll through a big list of items in a small area.

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