Results 1 to 20 of 28

Thread: ToolTip....

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ToolTip....

    Yes, for that you will have to use custom drawing.
    Tool tips are platform dependent. So on windows they actually look like a balloon.

    If you want them to look like that on Mac, then you have to paint them yourself. Either by using images, or drawing primitives, whatever.
    Since you are on a Mac, you could take advantage of the desktop composition features and add some need effects to it, like transparent gradations, etc.

    Regards

  2. The following user says thank you to marcel for this useful post:

    merry (1st August 2007)

  3. #2
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: ToolTip....

    THANX 4 the soln.

    But I dont know how to do custom drawing...

    Can u Explain me it with example

    thanx
    Always Believe in Urself
    Merry

  4. #3
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: ToolTip....

    Ok I 'll draw it using images and drawing primitives ..
    but how can i set it for the tooltip , so that tooltip should be displyed in that balloon.
    Always Believe in Urself
    Merry

  5. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ToolTip....

    Custom drawing is not that hard in general, but this tooltip problem will be pretty hard to solve.

    First of all, you have to subclass the event() function for the widget you want the tip to appear.
    In the event function you will look for a QHelpEvent, whose type is QEvent::ToolTip. This means that the widget is requested to show a tool tip.

    The second step is to subclass QToolTip and override the paintEvent. In paintEvent you do all the drawing.

    Qt Code:
    1. bool SomwWidget::event(QEvent* e)
    2. {
    3. QHelpEvent *he = static_cast<QHelpEvent*>(e);
    4. if(he && he->type() == QEvent::ToolTip)
    5. {
    6. if(!mCustomToolTip)
    7. mCustomToolTip = new CustomToolTip(this);
    8. mCustomToolTip->show();
    9. e->accept();
    10. return true;
    11. }
    12. else
    13. {
    14. if(mCustomToolTip)
    15. mCustomToolTip->hide();
    16. }
    17. return QWidget::event(e);
    18. }
    To copy to clipboard, switch view to plain text mode 
    mCustomToolTip should be a member of your widget's class, which you initialize to NULL in the constructor.

    For the paintEvent:
    Qt Code:
    1. void CustomToolTip::paintEvent()
    2. {
    3. QPainter p(this);
    4. p.fillRect(rect(), Qt::transparent );
    5. p.setBrush(Qt::red);
    6. p.drawEllipse(rect());
    7. }
    To copy to clipboard, switch view to plain text mode 


    This draws a red ellipse on a transparent background.
    It is just an example. You could customize the drawing further.

    Regards

  6. #5
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: ToolTip....

    Thanx 4 the solution

    Ok I ' ll try the solution.....
    Always Believe in Urself
    Merry

  7. #6
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: ToolTip....

    Hi Marcel

    mCustomToolTip should be a member of your widget's class, which you initialize to NULL in the constructor.
    Pls Explain the above line...

    Is it the member of the Subclass QToolTip.

    Thanx
    Always Believe in Urself
    Merry

  8. #7
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ToolTip....

    No.
    Let's assume that you want the custom tooltip be displayed for a button.
    Then you need to subclass QPushButton and override its event() function, where you put the code I've shown you earlier.
    The custom tooltip should be a member of this subclass.

    BTW, for what widget(s) you want a custom tooltip to be displayed?

    Regards

  9. #8
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: ToolTip....

    Hi...

    Qt Code:
    1. if(!mCustomToolTip)
    2. mCustomToolTip = new CustomToolTip(this);
    3. mCustomToolTip->show();
    To copy to clipboard, switch view to plain text mode 

    but in the above code u sent to me , Custom ToolTip is the SubClass Of QToolTip ..

    but now u said that the custom tooltip should be a member of QPushbutton subclass.

    Pls once again u view the code u sent to me and Explain it to me

    Thanx
    Always Believe in Urself
    Merry

  10. #9
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ToolTip....

    merry, merry, merry....
    First tell me for what widget you want your custom tooltip.

    Regards

  11. #10
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: ToolTip....

    QPushButton
    Always Believe in Urself
    Merry

  12. #11
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ToolTip....

    OK. So in order to display a custom tooltip for your push button, you have to intercept the QHelpEvent I mentioned earlier. For this you have to subclass QPushButton and override event().

    To display a custom tooltip you first need to create a custom tooltip.
    After you create it( create a class for it as I have explained ), add it as a member in your custom push button.

    Regards

  13. #12
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: ToolTip....

    Marcel

    I m doing like that only u said but when I Subclass QToolTip I got errors shown below :


    moc_CustomToolTip.cpp:37: error: 'staticMetaObject' is not a member of 'QToolTip'
    moc_CustomToolTip.cpp: In member function 'virtual void* CustomToolTip::qt_metacast(const char*)':
    moc_CustomToolTip.cpp:53: error: 'qt_metacast' is not a member of 'QToolTip'
    moc_CustomToolTip.cpp: In member function 'virtual int CustomToolTip::qt_metacall(QMetaObject::Call, int, void**)':
    moc_CustomToolTip.cpp:58: error: 'qt_metacall' is not a member of 'QToolTip'
    Thanx
    Always Believe in Urself
    Merry

  14. #13
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ToolTip....

    Can I see the code?

Similar Threads

  1. Tooltip on item in tableview
    By steg90 in forum Qt Programming
    Replies: 22
    Last Post: 17th May 2007, 11:03
  2. Moving Tooltip out of cursor-area
    By afo in forum KDE Forum
    Replies: 1
    Last Post: 7th January 2006, 15:13

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
  •  
Qt is a trademark of The Qt Company.