[Qt-interest] QMimeData problems between a QTableWidget and a QTreeWidget
Andrei Cimpean
andreiamenta at gmail.com
Mon Mar 22 09:59:11 CET 2010
Sweet, it works now.
But, I have another question. When I get with the item i want to drop into the tree, it shows me under the cursor something that looks like a block. The method works, but this detail is kinda bothering.
Is there something I need to set with drag->exec() method call in order to set this functionality or am I missing something in the tree class?
Thanks for the help.
On Mar 21, 2010, at 7:16 PM, Abhishek Patil wrote:
> Hi,
>
> Andrei Sebastian Cimpean wrote:
>>
>> Hello, i am trying to make it so when you drag from a table view to a
>> tree view you can send some data and add an item to the tree view.
>> I searched on the web and programmed something that i feel should
>> work but, alas, it is not.
>> This is the treeview class.
>>
>> Favorites::Favorites(QWidget *parent)
>> : QTreeWidget(parent)
>> {
>> //building the part for the favorites list
>> QTreeWidgetItem* favoritesItem = new QTreeWidgetItem();
>> favoritesItem->setText(0,"Favorites");
>> this->addTopLevelItem(favoritesItem);
>> favoritesItem->setExpanded(true);
>> this->setDragDropMode(QAbstractItemView::DropOnly);
>> this->setAcceptDrops(true);
>> addPathToFavorites(QString("asdsadasd"));
>> refreshFavorites();
>> }
>>
>> void Favorites::dragEnterEvent(QDragEnterEvent* event){
>> qDebug()<< event->mimeData()->text(); // just prints out ""
>> if (event->mimeData()->hasText())
>> event->acceptProposedAction();
>> }
>>
>> void Favorites::dropEvent(QDropEvent *event){
>> qDebug()<< event->mimeData()->text();
>> addPathToFavorites(event->mimeData()->text());
>> }
>>
>> And this is the table
>>
>> TableWidget::TableWidget(QWidget *parent)
>> : QTableWidget(parent)
>> {
>> //i've enabled drag in the main class
>> }
>>
>> void TableWidget::mousePressEvent(QMouseEvent *event){
>> if(event->button() == Qt::LeftButton)
>> poss = event->pos();
>> else { ;}
>> QTableWidget::mousePressEvent(event);
>> }
>>
>> void TableWidget::mouseMoveEvent(QMouseEvent *event){
>> if(!event->buttons() & Qt::LeftButton)
>> QTableWidget::mouseMoveEvent(event);
>> else
>> if((event->pos() - poss).manhattanLength() <
>> QApplication::startDragDistance())
>> QTableWidget::mouseMoveEvent(event);
>> else{
>> QTableWidgetItem *item = this->itemAt(event->pos());
>> if(item){
>> QDrag* drag = new QDrag(this);
>> QMimeData* mimeData = new QMimeData;
>> mimeData->setText(item->text());
>> drag->setMimeData(mimeData);
>> qDebug()<<drag->mimeData()->hasText()<<drag-
>>
>>> mimeData()->text();//print's what it should
>>>
> // I think you are missing
> drag->exec();
>> }
>> QTableWidget::mouseMoveEvent(event);
>> }
>> }
>>
>> What am I doing wrong? Any help will be greatly appreciated. Thank
>> you.
>>
>>
>> _______________________________________________
>> Qt-interest mailing list
>> Qt-interest at trolltech.com
>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>>
>
> --
> Abhishek Patil | http://thezeroth.net
> +91-9620022244 | abhishek at thezeroth.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100322/706b0fad/attachment.html
More information about the Qt-interest-old
mailing list