Ok,
I was just reading the documentation on Drag and Drop in the QT assistant and it shows an example using mousePressEvent which is what I was meant to say! I have this event in my tree widget, but it never gets called?
Code :
DAMessageTree
::DAMessageTree(QWidget *parent
){
ui.setupUi(this);
list << "Messages";
ui.treeList->setHeaderLabels( list );
ui.treeList->addTopLevelItem( pRoot );
ui.treeList->expandItem( pRoot );
QList<QTreeWidgetItem *> items;
if( theApp->m_dcb.m_oMessages.count() > 0 )
{
QHashIterator<QString,
QObject*> i
( theApp
->m_dcb.
m_oMessages );
while( i.hasNext() )
{
i.next();
CDADcb::CMessage* pMess = (CDADcb::CMessage*)i.value();
if( pMess )
{
newItem->setFlags( newItem->flags() | Qt::ItemIsUserCheckable );
//newItem->setCheckState(Qt::Unchecked);
newItem->setText( 0, pMess->name );
// store object with item for later retreivel
newItem
->setData
( 0, Qt
::UserRole,
QVariant::fromValue(pMess
) );
ui.treeList->addTopLevelItem( newItem );
ui.treeList->expandItem( newItem );
for( int i = 0; i < pMess->m_oSignals.count(); i++ )
{
CDADcb::CSignal* pSig = (CDADcb::CSignal*)pMess->m_oSignals.at(i);
if( pSig )
{
newSigItem
->setText
( 0,
QString( pSig
->name
) );
ui.treeList->addTopLevelItem( newSigItem );
}
}
}
}
}
}
DAMessageTree::~DAMessageTree()
{
}
void DAMessageTree
::mousePressEvent ( QMouseEvent * event
) {
}
DAMessageTree::DAMessageTree(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
QStringList list;
list << "Messages";
ui.treeList->setHeaderLabels( list );
QTreeWidgetItem* pRoot = new QTreeWidgetItem((QTreeWidget*)0,QStringList(QString("Can Messages")));
ui.treeList->addTopLevelItem( pRoot );
ui.treeList->expandItem( pRoot );
QList<QTreeWidgetItem *> items;
if( theApp->m_dcb.m_oMessages.count() > 0 )
{
QHashIterator<QString, QObject*> i( theApp->m_dcb.m_oMessages );
while( i.hasNext() )
{
i.next();
CDADcb::CMessage* pMess = (CDADcb::CMessage*)i.value();
if( pMess )
{
QTreeWidgetItem *newItem = new QTreeWidgetItem( pRoot );
newItem->setFlags( newItem->flags() | Qt::ItemIsUserCheckable );
//newItem->setCheckState(Qt::Unchecked);
newItem->setText( 0, pMess->name );
// store object with item for later retreivel
newItem->setData( 0, Qt::UserRole, QVariant::fromValue(pMess) );
ui.treeList->addTopLevelItem( newItem );
ui.treeList->expandItem( newItem );
for( int i = 0; i < pMess->m_oSignals.count(); i++ )
{
CDADcb::CSignal* pSig = (CDADcb::CSignal*)pMess->m_oSignals.at(i);
if( pSig )
{
QTreeWidgetItem *newSigItem = new QTreeWidgetItem( newItem );
newSigItem->setText( 0, QString( pSig->name ) );
ui.treeList->addTopLevelItem( newSigItem );
}
}
}
}
}
}
DAMessageTree::~DAMessageTree()
{
}
void DAMessageTree::mousePressEvent ( QMouseEvent * event )
{
}
To copy to clipboard, switch view to plain text mode
Something I'm doing wrong
Thanks,
Steve
Bookmarks