file selector in a qtablewidget - c++

I'm trying to get one cell in a QTableWidget to be a box with button at end"..." with file selector, but don't know how to change what kind of widget the cell is.

To control the types of cells in a table, it's best to use the QTableView class. Then, by using QItemDelegate you can make some table cell a button, to which you may bind a signal that opens a dialog.
I recommend starting by reading about delegate classes in the Qt docs.

Related

Edit QTableView with combo box in column

I created my own TableView and implemented model for it, etc. Finally, I started to edit values : it went well with flags and setData functions reimplemented, but I can only edit string/int values. I need to add possibility to select from combo box there. I saw topics like this one, but QTableView doesn't have a setCellWidget method.
Is there any possibility to implement it with QTableView or do I have to switch to 'TableWidget' and re-do my work (which would be problematic)?
QTableView has a method setIndexWidget() to display a widget in the particular cell. But in your case you should use a delegate derived from the QItemDelegate and reimplement the createEditor() method to create your combo-box.
Adding to Tomas's answer you will also need to reimplement the setEditorData and setModelData functions.
setEditorData is used to get the data from the model and set the initial value of the editor.
setModelData updates the data in the model according to the data entered in the editor.

Proper way to find out which Tab of QTabWidget is currently selected

I have a QTabWidget with several tabs, every tab containing a QTableWidget with numbers. Outside of this QTabWidget, I have one button. When the button is pressed, the currently selected widget should be processed. The QTableWidgets are identical in their structure, they just display numbers, and if I have a pointer to one of these widgets, I cannot deduce which tab it came from.
A simple method to identify which widget is currently selected is to call currentIndex(). But this will break when I reorder the tabs in the designer and is probably not working with movable tabs.
Another way is to use currentIndex() and tabText(int index). Like this I have a stable way to find out which tab is currently selected. The disadvantage of this is that I am then dependent on having unique tab texts, and I in general don't like to rely on a UI property to implement functionality.
My solution for now is to give every Widget a different accessible name that I can then read out like this:
QWidget* widget = tabWidget->currentWidget();
QString* name = widget->accessibleName();
This works, but I wonder if there is a better solution, something like the Qt::UserRole that can be assigned to any cell in a QTableWidget.

Changing QTreeview checkbox to icon without using stylesheets

I wanted to have a QTreeView with icons ( which act as a checkbox ) followed by some text from a subclass of QAbstractItemModel. I cannot modify or change the structure of this QAbstractItemModel.
When I use this QAbstractItemModel with QTreeview, it shows checkbox followed by some text and performs the intended function required. I just wanted to change this check box to on and off icons.
I found this:- Customizing the checkboxes of the items of a QTreeView
But, I cannot use stylesheets in my case as the icon I want to use some system icons which are loaded using icon loader which returns a KIcon instance ( subclass of QIcon ).
What would be the right way of doing this?
I saw this tutorial and tried creating an editor for a checkbox. But, how should I register editor as QVariant does not have Qt::CheckStateRole type?
I tried using Qt::Int, but it doesn't works

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