PDA

View Full Version : Drag and Drop problem



ScoOteR
17th December 2006, 17:17
Dear fellows,

i've looked over the forum first and didn' find any possible matching case. I'm trying to do drag and drop over a table view header. i've sub classed the tableview and the headers to implement their dragenterevent and dropevent. Also my model implements minmetype(). but draging is disabled over the header. i donno y, and i've debugged alot. any body got any idea !!!!!

wysota
17th December 2006, 17:43
Did you set acceptDrops property of the headerview to true? Did you implement mimeData() for your model (provided you want to drag items from the model)?

ScoOteR
19th December 2006, 15:11
yes all this stuff done, although my intention is to drop color item from another widget to the header of the tableview to color the columns.

wysota
19th December 2006, 15:28
Does the headerview receive dragenter and drop events? You can check that by installing an event filter on the header view.

ScoOteR
19th December 2006, 15:54
I've debugged it the header receives the dragenters event but it doesn't enter the drop event as the dropping is disabled as I've mentioned before. and yes i accept the drop action in the drag enters event.

ScoOteR
19th December 2006, 16:09
I've tried something else. I've made a simple model which holds some static data and made another widget for it the drop was enabled over this one. Even though both have the same custom table view and custom header and both models implements mimeType. So, what do u think made it work with one model and not the other !!!!!!!!!!!!!!!!!!!!!1:confused:

ScoOteR
19th December 2006, 16:17
actually I've a new surprise for u all. On debugging I found that it stops @ the break point in the mimeType of my temp small model. and i doesn't in the other model I've been working with for a while. So, I'd really appreciate if any body told me what the heck on earth could make what's happening here make sense !!!!:crying:

wysota
19th December 2006, 17:14
How did you enable drops for the header? Can you show the actual function call? Or maybe even a minimal compilable example?

ScoOteR
19th December 2006, 17:30
i think u didn't see my last post but any way here's the snippets u asked for



CHeader::CHeader(QWidget *parent)
: QHeaderView(Qt::Horizontal,parent)
{
ui.setupUi(this);
setAcceptDrops(true);
setDropIndicatorShown(true);
m_table = (CMyTable*)parent;
}


and here i associate this header to my custom table view


CCustomColumnTableView::CCustomColumnTableView(QWi dget *parent)
: QTableView(parent)
{
CHeader * temp = new CHeader(this);
setHorizontalHeader(temp);
.
.
}

wysota
19th December 2006, 17:39
What about dragEnter and drop events?

ScoOteR
19th December 2006, 18:35
void CHeader::dragEnterEvent(QDragEnterEvent * event)
{
if (event->mimeData()->hasFormat("application/x-color"))
event->acceptProposedAction();
}

void CHeader::dropEvent(QDropEvent * event)
{
m_table->dropEvent(event);
}

wysota
19th December 2006, 18:42
What happens if you drag over the header? Insert a debug statement and see if the handler gets triggered. It might be possible that the event is intercepted by the view in an event filter. If so, you have to either handle that event elsewhere or install another event filter to catch that event before the other filter gets it.

ScoOteR
19th December 2006, 19:16
Re: Drag and Drop problem
I've tried something else. I've made a simple model which holds some static data and made another widget for it the drop was enabled over this one. Even though both have the same custom table view and custom header and both models implements mimeType. So, what do u think made it work with one model and not the other !!!!!!!!!!!!!!!!!!!!!1

Re: Drag and Drop problem
actually I've a new surprise for u all. On debugging I found that it stops @ the break point in the mimeType of my temp small model. and i doesn't in the other model I've been working with for a while. So, I'd really appreciate if any body told me what the heck on earth could make what's happening here make sense !!!!

sorry but i think u've missed those to comments which I've posted early. So, I don't think it's related to the header or the table as those controls were common in the 2 previous cases!!!
I'm a bit confused as I'm finding all what's going is making no sense :eek:

and thanks a lot I really appreciate your interest.

wysota
19th December 2006, 19:35
Re: Drag and Drop problem
I've tried something else. I've made a simple model which holds some static data and made another widget for it the drop was enabled over this one. Even though both have the same custom table view and custom header and both models implements mimeType. So, what do u think made it work with one model and not the other !!!!!!!!!!!!!!!!!!!!!1
Was the "another widget" a headerview as well?


Re: Drag and Drop problem
actually I've a new surprise for u all. On debugging I found that it stops @ the break point in the mimeType of my temp small model. and i doesn't in the other model I've been working with for a while. So, I'd really appreciate if any body told me what the heck on earth could make what's happening here make sense !!!!
mimeTypes() just lists what types are produced by the model, it's not important for drops. You have to check whether drop actions are enabled over the place you want to drop on. The difference in behaviour between "two models" could be caused by a different implementation of the flags() method.

AFAIR normally a model doesn't differenciate between a drop on the header and "outside any item", so if you want to actually make a drop on the header, you have to hack the view (remember that headers are not part of the model).

For instance, if you return ItemIsDropEnabled from flags() for an invalid index, you'll be able to perform a drop directly on the view (and not on any of its items). But this won't be a drop on the header itself - you'll be able to drop anywhere in the view. I thought you wanted to drop on the header explicitely.


sorry but i think u've missed those to comments which I've posted early.
I haven't missed them, I just thought they didn't carry any relevant information.

ScoOteR
19th December 2006, 20:11
for your first question yes it had a headerview.

in both cases i used the same custom control I've made. So, what do u think might have caused this problem ?!

kpa
19th May 2010, 15:11
Hello all,

I am using QTableView with Qt4.6 and I have the same issue with Drop on QHeaderView.

I have Drag & drop working nicely on the table but not on the header. I have created a new class that is based on QHeaderView and that implement the dragEnterEvent, dragMoveEvent, dropEvent.
Of course I have setAcceptDrops(true).
None of the the implemented event is called, and dropping data to the header is impossible...

What I would like to do is to enable drag&drop for a complete line, by using the header.

Does anyone have any idea or hint ?

Thanks in advance

kpa

kpa
19th May 2010, 15:57
Finally it was only a bad validity check in dragEnterEvent