[Qt-interest] QStandardItemModel spread only with one click

David Boosalis david.boosalis at gmail.com
Sat Sep 25 06:40:53 CEST 2010


Oops hit the send button to soon, let me complete the slot below

On Fri, Sep 24, 2010 at 9:37 PM, David Boosalis <david.boosalis at gmail.com>wrote:

> If your using a QTreeView (I think it will work for QTreeWidget.
>
> You can capture the mouse event yourself test it and then emit a signal to
> expand all.  Something like this:
>
> void MyTreeView::mousePressEvent(QMouseEvent *me)
> {
>   QModelIndex index;
>   if (me->button() == Qt::RightButton) {  // or use left mouse button if
> you lie
>     index = indexAt(me->pos());
>     if (index.isValid()) {
>       me->accept();
>       emit itemClicked(index,me->globalPos());
>    }
>   else
>     QTreeView::mousePressEvent(me);
> }
>
>
> MyParentWidget::itemPressedSlot(ModelIndex mi, QPoint pos)
> {
>   QStandardItem *item = myModel->itemFromIndex(mi);
>   // perhaps you only want to expand if it is a root time
>
          QStandardItem  *parentItem = (QStandardlItem *) item->parent();
          if (!parentItem) {
             // do something else or nothing
         }
         else {
              myTree->expandAll();
         }
}



Hope this is of some help to you

David


On Tue, Sep 21, 2010 at 10:37 AM, Frank Lutz <frank422542 at googlemail.com>wrote:

> Hi,
>
> do there is a posability to modify the Model to click only one time at
> the item to spread the tree?
>
> Greetings
> frank
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100924/9896ae35/attachment.html 


More information about the Qt-interest-old mailing list