Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Drop Event Problem
Forum Updated to NodeBB v4.3 + New Features

Drop Event Problem

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 493 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DzCode
    wrote on last edited by DzCode
    #1

    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.

    1 Reply Last reply
    2
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      D 1 Reply Last reply
      0
      • SGaistS SGaist

        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.

        D Offline
        D Offline
        DzCode
        wrote on last edited by DzCode
        #3

        @SGaist

        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
        }
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          What do you mean by does not work ? Is it not called ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved