my problem is i want to add a new function to the item in teeview but the method of QAbstractItemModel::data(index,role) only give one checkbox or one icon to set
now i want to set two picture,which is clickable.
can it use the method of 'paint' or others?
Related
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.
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.
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!
how can I check what is displayed on the listView? More generally I need region occupied by those displayed item so I can paint another item below them.
If you need to add an item to the listview then you don't have to write any specific code for this. The list view contains the items of your model.
A QListView presents items stored in a model, either as a simple
non-hierarchical list, or as a collection of icons. This class is used
to provide lists and icon views that were previously provided by the
QListBox and QIconView classes, but using the more flexible approach
provided by Qt's model/view architecture.
Once the model items change a signal is emitted from the model and the view is repainted in order to display the modified items.
For more details check how the model/view programming in Qt works.
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