set subchild not to indent in qtreewidget when I expand them - c++

I have a QTreeWidget and I want children of a QTreeWidgetItem not indent when I expand them. I want to set the line only for top items. The first screenshot demonstrates what I would like to have, and the second what I am currently having. Would you please help me with how to change it to be like the first one? Thank you in advance!

This is not possible by QTreeWidget since you can only set the indentation globally. You would need to create your own class implementing this logic, e.g. QListWidgets connected to each other, or just a brand new tree widget implementation. You could also of course improve the existing QTreeWidget and send a patch.

Related

Qt: List of (custom) QWidgets without performance problems

I'm right now creating an Qt-application and have following problem:
I designed a custom QWidget with some labels and checkboxes. The application should now show a list of the custom QWidgets. I tried the QListWidget but is very slow for my use case. I want to add over 6000 elements of my custom QWidget. If I create these instances of the element and add it to the QListWidget the application will crashed.
Which is the best approach for my issue?
Thanks a lot!
As others have noted, QListWidget or QListView is the way to go. Also note that you should not display custom widgets with it, try using a custom QStyledItemDelegate instead and draw the items yourself. Depending on what you need, this can get complex really fast. I have used QTableView with this approach with tenth of thousands of items without performance problems.
If you really need to display custom widgets, check out a library I wrote some time ago for that exact purpose: longscroll-qt
.

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.

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.

How to customize the display of a QListView

I have implemented a list of users in my Qt program, using the model/view principle of Qt. My QListView displays a subclass of QAbstractListModel and so far this works just fine.
Now I would like to customize the display of my user list (display the name on several line, add IP information, and so on: not really relevant, I just want something really custom).
I couldn't find anything in the Qt documentation regarding this: what are my options ?
Note: The items in the list do not need to (can't) be modified, if this can help.
Thank you.
You need to create a new item delegate class to handle the painting. Here is a good answer to a similar question.