Page 1 of 2 12 LastLast
Results 1 to 20 of 28

Thread: ToolTip....

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

    Default ToolTip....

    Hi all

    Working on Qt4.2 for MAC

    Can any body tells me that , How can The tooltip for the button should be shown in some Image say "balloon".



    Thanx
    Always Believe in Urself
    Merry

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

    Default Re: ToolTip....

    Hi....

    I mean How can I display the tooltip for the QPushbutton in an image

    image can be of anytype

    1. Circle
    2. balloon
    3. triangle etc .....


    Thanx
    Always Believe in Urself
    Merry

  3. #3
    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....

    So you want to display an image with a QToolTip.
    Should be easy enough if you subclass QToolTip and override its paintEvent.
    The image, for example the triangle should contain the triangle in a specific color and the rest has to be a color different from the one the triangle has.
    This is to be able to create a heuristic mask (make the image transparent around the triangle ).
    Qt Code:
    1. QPixmap tipPix;
    2. //.. load the pixmap
    3. tipPix.setMask(tipPix.createHeuristicMask());
    To copy to clipboard, switch view to plain text mode 

    Another solution is to use a transparent png.

    Regards

  4. #4
    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 sol.

    But I dont want to display an image with the tooltip . I want to display toolTip (Text) in the balloon image....

    for eg.

    If I set the tooltip for the button ... It is drawn immediately below the given position in a distinctive black-on-yellow color combination in a rectangle, right , Now Instead of that rectangle I want to use balloon.

    Thanx
    Always Believe in Urself
    Merry

  5. #5
    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

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

    merry (1st August 2007)

  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....

    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

  8. #7
    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

  9. #8
    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

  10. #9
    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

  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....

    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

  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....

    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

  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....

    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

  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....

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

    Regards

  15. #14
    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

  16. #15
    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

  17. #16
    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

  18. #17
    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?

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

    Default Re: ToolTip....

    Yaa Sure...

    QButton.cpp //Subclass of QPushButton

    Qt Code:
    1. #include "QButton.h"
    2. #include <QEvent>
    3. #include <QHelpEvent>
    4.  
    5.  
    6. MyToolTipButton::MyToolTipButton(QWidget *parent ): QPushButton(parent)
    7. {
    8.  
    9. MyToolTipButton1 = new QPushButton();
    10. MyToolTipButton1->setText("abc");
    11. }
    12.  
    13.  
    14.  
    15. bool MyToolTipButton::event(QEvent* e)
    16. {
    17. QHelpEvent *he = static_cast<QHelpEvent*>(e);
    18. if(he && he->type() == QEvent::ToolTip)
    19. {
    20. if(!mCustomToolTip)
    21. //mCustomToolTip = new CustomToolTip();
    22. MyToolTipButton1->show();
    23. e->accept();
    24. return true;
    25. }
    26. else
    27. {
    28. if(mCustomToolTip)
    29. MyToolTipButton1->hide();
    30. }
    31.  
    32. return QWidget::event(e);
    33.  
    34. }
    To copy to clipboard, switch view to plain text mode 

    QButton.h

    Qt Code:
    1. #ifndef QBUTTON_H
    2. #define QBUTTON_H
    3.  
    4. #include <QPushButton>
    5. #include <QEvent>
    6. #include "CustomToolTip.h"
    7.  
    8. class CustomToolTip;
    9. class MyToolTipButton : public QPushButton
    10. {
    11. Q_OBJECT
    12. public:
    13. MyToolTipButton(QWidget *parent =0);
    14.  
    15. public:
    16. QPushButton *MyToolTipButton1;
    17.  
    18. protected:
    19. bool event(QEvent* e);
    20.  
    21.  
    22. public:
    23. CustomToolTip *mCustomToolTip;
    24.  
    25. };
    26.  
    27.  
    28. #endif
    To copy to clipboard, switch view to plain text mode 

    CustomToolTip.h

    Qt Code:
    1. #ifndef CustomToolTip_H
    2. #define CustomToolTip_H
    3. #include <QToolTip>
    4.  
    5. class CustomToolTip : public QToolTip
    6. {
    7. Q_OBJECT
    8. public:
    9. CustomToolTip();
    10. public:
    11. void paintEvent() ;
    12.  
    13. };
    14.  
    15. #endif
    To copy to clipboard, switch view to plain text mode 


    CustomToolTip.cpp

    Qt Code:
    1. #include "CustomToolTip.h"
    2. #include <QPainter>
    3.  
    4. void CustomToolTip::paintEvent()
    5. {
    6. QPainter p(this);
    7. p.fillRect(rect(), Qt::transparent );
    8. p.setBrush(Qt::red);
    9. p.drawEllipse(rect());
    10. }
    To copy to clipboard, switch view to plain text mode 

    and also there is an error
    CustomToolTip.cpp:15: error: no matching function for call to 'QPainter::QPainter(CustomToolTip* const)'
    Always Believe in Urself
    Merry

  20. #19
    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....

    You have a lot of errors there!
    Most important:
    1. Remove the QPushButton member from the QPushButton subclass.
    2. paintEvent is virtual protected. Define it as such.
    Also, it has a QPaintEvent* parameter.

    Regards

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

    Default Re: ToolTip....

    After doing all the things u said , I Still got these three errors

    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'
    Always Believe in Urself
    Merry

Similar Threads

  1. Tooltip on item in tableview
    By steg90 in forum Qt Programming
    Replies: 22
    Last Post: 17th May 2007, 12:03
  2. Moving Tooltip out of cursor-area
    By afo in forum KDE Forum
    Replies: 1
    Last Post: 7th January 2006, 16: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.