[Qt-interest] Re some questions about qtreewidget , context menu and items

jialrs jialrs at 126.com
Wed Jul 7 02:28:26 CEST 2010


i am sorry ,there is something wrong with my e-mai client , so i sent my e-mail again ....
thank you for you help
>you could use itemClicked() signal and QApplication::mouseButtons() to determine right button, 
>or inherit QTreeWidget and override mousePressEvent() and use itemAt() to recognize which item was clicked

i have finish this function , but a little different , i inherit QTreeWidget and override mousePressEvent , but i 
have defined a bool value when i press right button i set it true , otherwise false; and i also use itemClicked() 
signal, the fellow is my code:

void VedioTree::mousePressEvent(QMouseEvent *event)
{
    if (event->button()== Qt::RightButton)
    {
        ifItemClicked = true;
    }
    else
    {
        ifItemClicked = false;
    }
    QTreeWidget::mousePressEvent(event);
}

void VedioTree::onItemClick(QTreeWidgetItem *item, int c)
{
    if (ifItemClicked && this->currentItem()->parent()!= NULL)
    {
        listMenu->exec(QCursor::pos());
    }
}

i use this->currentItem()->parent()!= NULL to decide wether it is a top level item;

>probably you have to remove item and insert it again at different position (I'm not sure if remove
> is necessary if you insert the same item at different)

but i has already tried this methed it doesn't do well ,because when insert it back , the widget on the item
disappear,too....
i just suppose the item doesn't contains the widget , so , when we move it , the widget will not go with the 
item , so how can i make the widget go with the item when i drag the item or i change the position ?
please help me ....

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100707/e08b17f9/attachment.html 


More information about the Qt-interest-old mailing list