» How to render a a complex widget inside a tree view item in QT?
How to render a a complex widget inside a tree view item in QT?
|January 26, 2010
Posted by forumadmin
I have the following problem with QT model/view framework. I want to render a widget inside a table view item.
First my thought was to use
void QAbstractItemView::setIndexWidget( const QModelIndex & index, QWidget * widget )
But the documentation for this function explicitly states:
This function should only be used to
display static content within the
visible area corresponding to an item
of data. If you want to display custom
dynamic content or implement a custom
editor widget, subclass QItemDelegate
So they propose to use delegates here. Well, so far so good. I know that the delegates may be used to create an editor, which may be basically any QT widget. But here is the problem – I don’t want this widget to be an editor – I want to render the item with this widget always. And not just “render”, I need it to have the exact behavior of the widget.
Now the widget I want to use is a custom widget, which is a container of some other widgets (few check-boxes, few buttons with some layout).
The solution I consider is like this:
- Grab the look of my custom widget to a pixmap.
- Let the delegate paint itself using this pixmap.
- When the mouse is over an item cause the view to automatically start editing (I don’t
know how to do it yet, but I suppose it’s possible)
- Let the delegate create my widget as the editor for an item.
This solution seems to work, but it smells bad for me. Can anyone thing about more elegant solution for this problem?
More Related Questions
- Qt jpg image display I want to display .jpg image in an Qt UI. I checked it online and found http://doc.trolltech.com/4.2/widgets-imageviewer.html. I thought Graphics View will do the same, and also it has […]
- Using a QComboBox to Edit a ForeignKey in a QAbstractTableModel referencing another QAbstractTableModel I'm currently programming an application in Qt using the Model/View architecture and I now ran into a problem that I haven't found a solution to so far.
I've got 2 […]
- QTreeWidget vertical scrollbar jumps too far I have a QTreeWidget in my application that is populated by a user selection elsewhere. The contents of the first column of treewidget is other custom qt widgets based on the users […]
- setting a delegate for a custom view inside a uitableview cell I am not sure if that's possible.
So I have a custom cell - which inside contains a custom uiview. This UIView is a view that displays bar diagrams. So I want to set the dataSource, and […]
- Dynamically change GridView item template I have a fairly big asp.net website that use GridView bound to the same object in lots of places. I'm using an item template to customize each row. However to have the same template in all […]
- error in adding matplotlib widget into pyqt4 I was trying to add a custom widget into qtdesginer using following code
from PyQt4 import QtGui
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
- Copying delegates I was just reading a page on events on MSDN, and I came across a snippet of example code that is puzzling me.
The code in question is this:
// Make a temporary copy of the event to avoid […]
- Delegate is nil I have a property on a ViewController which I set from a parent SplitViewController:
@interface DownloadRecipesViewController_iPad : […]
- What is a C++ delegate? What is the general idea of a delegate in C++? What are they, how are they used and what are they used for?
I'd like to first learn about them in a 'black box' way, but a bit of […]
- Is it possible to have a delegate as attribute parameter? Is it possible to have a delegate as the parameter of an attribute?
public delegate IPropertySet ConnectionPropertiesDelegate();
public static class TestDelegate