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. Offset for QHelpEvent pos() function

Offset for QHelpEvent pos() function

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.7k Views
  • 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.
  • A Offline
    A Offline
    Anticross
    wrote on last edited by
    #1

    Why in such code i get the wrong item ?

    @if (event->type() == QEvent::ToolTip) {
    QHelpEvent * helpEvent = static_cast<QHelpEvent *>(event);

    QTableWidgetItem * item = itemAt(helpEvent->pos());

        if (item != NULL)
    

    QToolTip::showText(helpEvent->globalPos(), GET_ADDRESS_BOOK()->getContactName(item->data(Qt::EditRole).toInt()));
    else
    QToolTip::showText(helpEvent->globalPos(), "");
    }

    return QTableWidget::event(event);@

    If I add some offset in size of my vertical end horizontal header, then I have right item. So I modify my code like this:
    @ if (event->type() == QEvent::ToolTip) {
    QHelpEvent * helpEvent = static_cast<QHelpEvent *>(event);

    int y = horizontalHeaderItem(0)->sizeHint().height();
    int x = verticalHeaderItem(0)->sizeHint().width();

    QTableWidgetItem * item = itemAt(helpEvent->pos() - QPoint(x,y));

        if (item != NULL)
    

    QToolTip::showText(helpEvent->globalPos(), GET_ADDRESS_BOOK()->getContactName(item->data(Qt::EditRole).toInt()));
    else
    QToolTip::showText(helpEvent->globalPos(), "");
    }

    return QTableWidget::event(event);@
    Is there any other way to solve this problem ?

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tobias.hunger
      wrote on last edited by
      #2

      Have you considered using QTableWidgetItem::setToolTip(...)?

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sven.bergner
        wrote on last edited by
        #3

        You can use mapToGlobal(), mapFromGlobal() or mapTo() to get the right offset.
        Each widget is positioned relativ to its parent.

        Coding less and creating more with every new version of Qt a bit more.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Anticross
          wrote on last edited by
          #4

          Thanks. mapFromGlobal() is that thing that I searching for.

          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