Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7415693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:21:05+00:00 2026-05-29T07:21:05+00:00

How can I change the mouse icon when the mouse is over the text

  • 0

How can I change the mouse icon when the mouse is over the text in item delegate?
I have this part, but I can’t find any example to change the mouse pointer.

What am I missing?

   void ListItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
                             const QModelIndex &index) const
    {
     if (index.isValid())
        {
      int j = index.column();
      if(j==4)
      {
       QString headerText_DisplayRole = index.data(Qt::DisplayRole).toString() ;
       QApplication::style()->drawPrimitive( QStyle::PE_PanelItemViewItem, &option, painter );

       QFont font = QApplication::font();
       QRect headerRect = option.rect;
       font.setBold(true);
       font.setUnderline(true);
       painter->setFont(font);
       painter->setPen(QPen(option.palette.brush(QPalette::Text), 0));
       const bool isSelected = option.state & QStyle::State_Selected;    
       if (isSelected)
        painter->setPen(QPen(option.palette.brush(QPalette::HighlightedText), 0));
       else
        painter->setPen(QPen(option.palette.brush(QPalette::Text), 0));
       painter->save();    
       painter->drawText(headerRect,headerText_DisplayRole);
       painter->restore();
       bool hover = false;
       if ( option.state & QStyle::State_MouseOver )
       {
           hover = true;
       }
       if(hover)
       {
        // THIS part i missing , how detect when mouse is over the text
        // and if its over how to change the icon of the mouse?
       }


      }
      else
      {
       QStyledItemDelegate::paint(painter, option, index);
      }
     }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T07:21:06+00:00Added an answer on May 29, 2026 at 7:21 am

    First of all you will need the mouse position. You can get it using the QCursor::pos static function.

    QPoint globalCursorPos = QCursor::pos();
    

    Notice that the result is in global screen coordinates, so you will have to translate it in widget coordinates. Let’s assume that the widget on which you are using the delegate is called myWidget. In order to do the translation you will need the mapFromGlobal function of QWidget

    QPoint widgetPos = myWidget->mapFromGlobal(globalCursorPos);
    

    Finally you are going to need the indexAt from QAbstractItemView which returns the model index of the item at the viewport coordinates point.

    If myView is the name of the view you are using then the index at the current position is:

    QModelIndex currentIndex = myView->itemAt(widgetPos);
    

    Notice that you may need the viewport() in order to be precise. In this case in order to map the global coordinates you will need:

    QPoint viewportPos = myWidget->viewport()->mapFromGlobal(globalCursorPos);
    

    Finally you have to check if the returned index from the itemAt is the same with the index in your paint function. If yes change the cursor to whta you want, else restore the default cursor

    if(hover)
    {
         QPoint globalCursorPos = QCursor::pos();
         QPoint viewportPos = myWidget->viewport()->mapFromGlobal(globalCursorPos);
         QModelIndex currentIndex = myView->itemAt(widgetPos);
    
         if (currentIndex == index)
             QApplication::setOverrideCursor(QCursor(Qt::PointingHandCursor)); 
         else
             QApplication::restoreOverrideCursor(); 
    }
    

    This is the basic idea. Another option would be to reimplement the mouseMoveEvent and implement the functionality there. Check this blog post for more details.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

You can change the connection string at run-time like this. You make the connection
Is there an app that can change the order of images inside an icon?
Is there any way that I can change how a Literal of a code
Is there a way I can change the default system mouse pointer from within
I'm making a text editor using Text Area. Which user can change font size,
How can I find out the mouse position in a browser? I know e.pageX
I have an application in which you can do a right mouse button press
How can i change the mouse pointer to an image when clicked on the
In the following example, a mouse hover over each link changes the image: http://www.prism.gatech.edu/~dm257/sprite.html
I would like to know how I can change mouse position in MouseProc function.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.