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. [solved] mousePressEvent on qtableview
Forum Updated to NodeBB v4.3 + New Features

[solved] mousePressEvent on qtableview

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 4.5k 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.
  • B Offline
    B Offline
    broadpeak
    wrote on last edited by
    #1

    I cannot get the mousePressEvent on my qtableview.
    I'd like to select one row, but no one is selected.
    (I'd like to drag one row and drop it into somewhere.)
    How can I solve this?

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      Do you call the base class QTableView::mousePressEvent() in your mousePressEvent()?

      Or don't you get no event in the first place?

      1 Reply Last reply
      0
      • B Offline
        B Offline
        broadpeak
        wrote on last edited by
        #3

        [quote author="Lukas Geyer" date="1357553560"]Do you call the base class QTableView::mousePressEvent() in your mousePressEvent()?

        Or don't you get no event in the first place?[/quote]

        More exactly:

        Now I get mousePressEvent(), but no row is selected (highlighted)! I cannot get the row (cell) content. I need a cell content to my mime data for dragging.
        (In the model I set correctly the flag that item is ItemIsSelectable.)

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lgeyer
          wrote on last edited by
          #4

          If your overridden mousePressEvent() calls QTableView::mousePressEvent() it should behave exactly the same.

          But what do you want to achieve in the first place?

          If it is about enabling drag support with a custom MIME type just enable dragging, <code>QTableView::setDragDropMode(QAbstractItemView::DragOnly)</code> and either reimplement QAbstractItemModel::mimeData() in your model or override QAbstractItemView::startDrag() to provide your own QMimeData / QDrag object.

          1 Reply Last reply
          0
          • B Offline
            B Offline
            broadpeak
            wrote on last edited by
            #5

            [quote author="Lukas Geyer" date="1357559553"]If your overridden mousePressEvent() calls QTableView::mousePressEvent() it should behave exactly the same.

            But what do you want to achieve in the first place?

            If it is about enabling drag support with a custom MIME type just enable dragging, <code>QTableView::setDragDropMode(QAbstractItemView::DragOnly)</code> and either reimplement QAbstractItemModel::mimeData() in your model or override QAbstractItemView::startDrag() to provide your own QMimeData / QDrag object.[/quote]

            Yeaaaaaaaaah!
            startDrag() was the solution!
            Many thanks :)

            1 Reply Last reply
            0
            • L Offline
              L Offline
              lgeyer
              wrote on last edited by
              #6

              You're welcome.

              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