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. Tooltip for each Qplieslice in a QPieSeries
Forum Updated to NodeBB v4.3 + New Features

Tooltip for each Qplieslice in a QPieSeries

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 336 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.
  • M Offline
    M Offline
    Mary_M
    wrote on last edited by Mary_M
    #1

    Hi all,

    My widget includes Qpieslices in a QpieSeries. I need to show the slices' values while hovering on them. I need a tooltip to show the value of the current slice that the mouse is hovering on it. Also, as long as the cursor is on a slice, the tooltip should constantly show its value.

    I used different methods including the following code.

    Widget::Widget(QWidget *parent)
        : QWidget(parent)
    {
        setMouseTracking(true);
    // some code
        QPieSlice *slice = new QPieSlice("Space", value);
    //some code
        connect(slice, &QPieSlice::hovered, this, &Widget::explodeSlice);
    //some code
    

    In explodeSlice I do some works that is not related to the tooltip.

    bool Widget::event (QEvent *ev)
    {
            label_ev = new QLabel;
            label_ev->setWindowFlag(Qt::ToolTip);
            QHelpEvent *helpEvent = static_cast<QHelpEvent *>(ev);
            label_ev->move(helpEvent->globalPos());
            label_ev->setText(txt);
            label_ev->show();
    
            return QWidget::event(ev);
    }
    
    

    In this code, I have got two problems. First, a delay in the tooltip to pop up (I enabled mouse-tracking mode in my widget). Second, Where can I hide it? the tooltip remains on the slice and wherever I want to hide it in my code it does not work. No way to hide it.
    Could anyone help me with this?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      myk321
      wrote on last edited by
      #2

      In terms of when to hide, Qt 6.6 has a different hovered() signature which includes a bool, which is set to true on mouse over and false on mouse exit. so:

      void xyzObject::slotSliceHover(bool hovered){
          QPieSlice* hoverSlice = qobject_cast<QPieSlice*>(QObject::sender());
          if (hoverSlice != nullptr){
              if (hovered)
                  hoverSlice->setExploded(true);
              else
                  hoverSlice->setExploded(false);
          }
      }
      
      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