Drop Event Problem
-
I am coding my own class for QHeaderView, and I implemented dropEvent of QHeaderView, but it doesnot work even if I set true dragging and dropping for the view. Is there any solution for that. It is necessary for column dragging dropping from one view to another view.
Also, events about dragging do not work.
-
Hi,
What you are trying to achieve is not clear and without code we can't really guess what is going on. So please explain what you want to do exactly and show the code you are currently using.
-
The code for header view is like below. I have two tableview. I want to implement column drag/drop from one table to another table.
I will look at mime data and make dragged column hidden in the first table, and show it in the second since the both table use the same data model, but visibility of columns is the only difference. However, drop event does not work. I could not understand what is wrong.
void HorizontalHeader::mouseMoveEvent(QMouseEvent *in_p_event) { if (true == m_fixed_columns.isEmpty()) { QHeaderView::mouseMoveEvent(in_p_event); return; } if (Qt::LeftButton & in_p_event->buttons() && false == m_drag_start_pos.isNull() && (in_p_event->pos() - m_drag_start_pos).manhattanLength() >= QApplication::startDragDistance()) { int column = logicalIndexAt(m_drag_start_pos); QDrag drag(this); QByteArray data_byte; QDataStream data_stream(&data_byte, QIODevice::WriteOnly); data_stream << column; QMimeData *p_mime_data = new QMimeData(); p_mime_data->setData("headercolumn", data_byte); drag.setMimeData(p_mime_data); Qt::DropAction action = drag.exec(Qt::MoveAction); if (Qt::IgnoreAction != action) { hideSection(column); } else QHeaderView::mouseMoveEvent(in_p_event); } else QHeaderView::mouseMoveEvent(in_p_event); } void HorizontalHeader::mousePressEvent(QMouseEvent *in_p_event) { if (true == m_fixed_columns.isEmpty()) { QHeaderView::mousePressEvent(in_p_event); return; } if (Qt::LeftButton == in_p_event->button()) { m_drag_start_pos = in_p_event->pos(); } QHeaderView::mousePressEvent(in_p_event); } void HorizontalHeader::dropEvent(QDropEvent *in_p_event) { const QMimeData *p_mime_data = in_p_event->mimeData(); qDebug() << "p_mime_data: " << p_mime_data; //check mime data and put the column into other qtableview }
-
What do you mean by does not work ? Is it not called ?