How to make QLabel text selectble in QStyledItemDelegate type of class
-
Thanks For the replay
wow .. is there some other simple solution for selectable text ?
i dont absolutely need QLabel not at all i just wanted to present text that is selectable in the
itemdelegate . what more "easy" options do i have ?
i have more elements in the paint methods that im presenting like images.also im using QListView so i can't use : setItemWidget
-
@
pseudo code
class QModelIndex;
IView {
public:
virtual void setSelected(const QModelIndex& index, bool flag) = 0;
}MyListView : public QListView, public IView {
ItemDelegate *delegate;public: MyListView(QWidget *parent = 0) : QListView(parent) { delegate = new ItemDelegate; delegate->setView(this); setItemDelegate(delegate); } void setSelected(const QModelIndex& index, bool flag) { QListWidgetItem *item = item(index.row()); MyWidget *w = static_cast<MyWidget*>(itemWidget(item)); w->setSelected(flag); }}
void ItemDelegate::setView(IView *view)
{
this->view = view; //pimpl
}void ItemDelegate::paint (QPainter* p, const QStyleOptionViewIte& o, const QModelIndex& i) const
{
QStyleOptionViewItemV4 option = o;initStyleOption(&option, i); bool selected = ( option.state & QStyle::State_Selected ); view->setSelected(i, selected);QSyledItemDelegate::paint(p, o, i);
}
@ -
I gather you need to have text selectable for a read-only table, right?
So... what you could try, is to set QLabel as your 'editor' by using a custom delegate or by using a class like [[doc:QItemEditorCreator]] or [[doc:QStandardItemEditorCreator]]. Then, you could use a [[doc:QIdentityProxyModel]] to make the cells in your table writable again. That way, when you click a table cell, the editor will be used. However, in this case the editor will be a QLabel: still not editable, but selectable nontheless.
-
Ok i found great solution , i really what you to say what you think ,
after looking at the code of "QTwitter":http://qt-apps.org/content/show.php/qTwitter?content=99087 , i saw it uses custom widget as the item
i mean widget that made in the Q Designer .