Results 1 to 7 of 7

Thread: Setting a cursor on QTextEdit

  1. #1
    Join Date
    Nov 2006
    Posts
    29
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Default Setting a cursor on QTextEdit

    Hi!
    Was just wondering how to set the mouse cursor on the QTextEdit.
    setCursor() doesn't work.
    viewPort()->setCursor() does work, but when I compile the program to an *.exe, and run it, that line makes it crash.

    And I don't want to use QApplication::setOverrideCursor...

    Anyone able to help me?

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Setting a cursor on QTextEdit

    setCursor() doesn't work.
    Sure it doesn, if you use it right!

    Show us your code.

  3. #3
    Join Date
    Nov 2006
    Posts
    29
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Default Re: Setting a cursor on QTextEdit

    Quite simple:
    The pointing hand cursor won't override the default IBeam (isn't it ?)

    Qt Code:
    1. #include "myclass.h"
    2. myClass::myClass(QWidget *parent)
    3. : QTextEdit(parent)
    4. {
    5. setMouseTracking(true);
    6. }
    7.  
    8. myClass::~myClass()
    9. {
    10.  
    11. }
    12.  
    13. void myClass::mouseMoveEvent(QMouseEvent *event)
    14. {
    15. setCursor(Qt::PointingHandCursor);
    16. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Setting a cursor on QTextEdit

    Try
    Qt Code:
    1. viewport()->setMouseTracking(true);
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  5. #5
    Join Date
    Nov 2006
    Posts
    29
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Default Re: Setting a cursor on QTextEdit

    But wouldn't that just help if mouseMoveEvent wasn't called?
    Because mouseMoveEvent is getting called everytime I move the mouse.
    setCursor() just doesn't work for me

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Setting a cursor on QTextEdit

    How about
    Qt Code:
    1. viewport()->setCursor(Qt::PointingHandCursor);
    To copy to clipboard, switch view to plain text mode 
    then?
    J-P Nurmi

  7. #7
    Join Date
    Nov 2006
    Posts
    29
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Default Re: Setting a cursor on QTextEdit

    Quote Originally Posted by Erlendhg View Post
    viewPort()->setCursor() does work, but when I compile the program to an *.exe, and run it, that line makes it crash.
    The weird about this is that in my new little test program
    Qt Code:
    1. #include "myclass.h"
    2.  
    3. myClass::myClass(QWidget *parent)
    4. : QTextEdit(parent)
    5. {
    6. viewport()->setCursor(Qt::PointingHandCursor);
    7. }
    8.  
    9. myClass::~myClass()
    10. {
    11.  
    12. }
    To copy to clipboard, switch view to plain text mode 

    that actually does work, but not in my big program.

    *scratching my head*

    Well, this does work for me anyway:
    Qt Code:
    1. QWidget *viewPort = viewport();
    2. viewPort->setCursor(Qt::PointingHandCursor);
    3. setViewport(viewPort);
    To copy to clipboard, switch view to plain text mode 

  8. The following user says thank you to Erlendhg for this useful post:

    anju123 (14th August 2007)

Similar Threads

  1. Re-implement mouse events of QTextEdit
    By Ankitha Varsha in forum Qt Programming
    Replies: 2
    Last Post: 14th October 2006, 17:55
  2. setting cursor problem in QTextEdit
    By jyoti kumar in forum Qt Programming
    Replies: 3
    Last Post: 19th May 2006, 09:17
  3. QTextEdit API questions (plain text)
    By Gaspar in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 07:03
  4. [QT 4] QTextEdit performance
    By fellobo in forum Qt Programming
    Replies: 8
    Last Post: 6th March 2006, 20:27
  5. Obtaining clean (x)html from QTextEdit
    By ccf_h in forum Qt Programming
    Replies: 1
    Last Post: 5th February 2006, 15:47

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.