Page 2 of 2 FirstFirst 12
Results 21 to 28 of 28

Thread: ToolTip....

  1. #21
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ToolTip....

    QToolTip is not a QObject... remove the Q_OBJECT macro...
    Current Qt projects : QCodeEdit, RotiDeCode

  2. #22
    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....

    In this case change the inheritance from QToolTip to QWidget.
    And in the constructor of CustomToolTip:
    Qt Code:
    1. setWindowFlags(Qt::ToolTip);
    To copy to clipboard, switch view to plain text mode 

    Regards

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


    I had done all that what u said , It gives no error but ,only showing a Main window with a button and toolTip of that button in a rectangle but not showing the ToolTip in an elliplse.

    I debug the code , And on debugging I found that Its not entering in this function

    Qt Code:
    1. if(he && he->type() == QEvent::ToolTip)
    2. {
    3. if(!mCustomToolTip)
    4. mCustomToolTip = new CustomToolTip(this);
    5. mCustomToolTip->show();
    6. e->accept();
    7. return true;
    8. }
    To copy to clipboard, switch view to plain text mode 


    Pls help What can I do now.

    Thanx
    Last edited by merry; 2nd August 2007 at 08:18. Reason: updated contents
    Always Believe in Urself
    Merry

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

    Default Re: ToolTip....

    Pls...Pls............help
    Always Believe in Urself
    Merry

  5. #25
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ToolTip....

    Quote Originally Posted by merry View Post
    Pls...Pls............help
    Firstly, in the CustomToolTip class do this
    Qt Code:
    1. CustomToolTip::CustomToolTip( QWidget * parent )
    2. :QWidget(parent)
    3. {
    4. setWindowFlags(Qt::ToolTip);
    5. resize( 50, 50 );
    6. }
    To copy to clipboard, switch view to plain text mode 

    Keep the mouse cursor stable on the PushButton and then move, a red ecllipse will appear on top left corner.

    Works fine for me.

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

    Default Re: ToolTip....

    Thanx Mr Rajeev For helping me ..

    I do the same as u said but still not showing tooltip..


    Pls review my code once , and Also tells me Is am doin somthin Wrong...


    CustomToolTip.cpp

    Qt Code:
    1. #include "CustomToolTip.h"
    2. #include <QPainter>
    3.  
    4. CustomToolTip::CustomToolTip( QWidget * parent )
    5. :QWidget(parent)
    6. {
    7. setWindowFlags(Qt::ToolTip);
    8. resize(50,50);
    9. }
    10.  
    11.  
    12. void CustomToolTip::paintEvent(QPaintEvent *e)
    13. {
    14. QPainter p(this);
    15. p.fillRect(rect(), Qt::transparent );
    16. p.setBrush(Qt::red);
    17. p.drawEllipse(rect());
    18. }
    To copy to clipboard, switch view to plain text mode 


    QButton.cpp



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

    MainWindow.cpp

    Qt Code:
    1. #include "MainWindow.h"
    2. #include "QButton.h"
    3. #include <QtGui>
    4.  
    5.  
    6. MainWindow::MainWindow()
    7. {
    8. QWidget *centralWidget = new QWidget;
    9. button=new MyToolTipButton(0);
    10. centralWidget->setFixedSize(500,300);
    11. button->FileRecovery = new QPushButton();
    12. button->FileRecovery->setGeometry(20,20,121,121);
    13. button->FileRecovery->setFixedSize(121,121);
    14. button->FileRecovery->setToolTip("Hello");
    15. button->FileRecovery->setIcon(QIcon("/design/images/open drive.png"));
    16. button->FileRecovery->setIconSize(QSize(64,64));
    17. button->RawRecovery = new QPushButton();
    18. button->RawRecovery->setGeometry(140,20,121,121);
    19. button->RawRecovery->setFixedSize(121,121);
    20. button->RawRecovery->setIcon(QIcon("/design/images/save& repair -6 copy.png"));
    21. button->RawRecovery->setIconSize(QSize(64,64));
    22. clipboard = QApplication::clipboard();
    23. QHBoxLayout *controlsLayout = new QHBoxLayout;
    24. controlsLayout->addStretch(1);
    25. QHBoxLayout *lineLayout = new QHBoxLayout;
    26. lineLayout->addSpacing(1);
    27. QVBoxLayout *centralLayout = new QVBoxLayout;
    28. centralLayout->addLayout(controlsLayout);
    29. centralLayout->addWidget(button->FileRecovery, 1);
    30. centralLayout->addWidget(button->RawRecovery, 0);
    31. centralLayout->addSpacing(1);
    32. centralLayout->addLayout(lineLayout);
    33. centralWidget->setLayout(centralLayout);
    34. setCentralWidget(centralWidget);
    35. button->FileRecovery->installEventFilter(this);
    36. }
    To copy to clipboard, switch view to plain text mode 

    Regards
    Always Believe in Urself
    Merry

  7. #27
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ToolTip....

    Ok, no time to review.
    What you can do is take the below code, cut and paste into a new project and then try.
    NOTE: you have to place the mouse cursor on the button stable for a while, then move slightly to see the eclipse.

    //.h
    Qt Code:
    1. class PushButton : public QPushButton
    2. {
    3. Q_OBJECT
    4. public:
    5. PushButton( const QString & text, QWidget * parent = 0 );
    6. ~PushButton(){}
    7.  
    8. protected:
    9. bool event ( QEvent * );
    10. void mouseMoveEvent( QMouseEvent* );
    11.  
    12. private:
    13. CustomToolTip *mCustomToolTip;
    14. QPoint _mousePoint;
    15. };
    To copy to clipboard, switch view to plain text mode 
    //.cpp
    Qt Code:
    1. PushButton::PushButton( const QString & text, QWidget * parent )
    2. : QPushButton(parent)
    3. {
    4. setText(text);
    5. mCustomToolTip = 0;
    6. setMouseTracking(true);
    7. }
    8.  
    9. bool PushButton::event( QEvent * e )
    10. {
    11. QHelpEvent *he = static_cast<QHelpEvent*>(e);
    12. if(he && he->type() == QEvent::ToolTip)
    13. {
    14. if(!mCustomToolTip)
    15. mCustomToolTip = new CustomToolTip( this);
    16. mCustomToolTip->show();
    17. e->accept();
    18. return true;
    19. }
    20. else
    21. {
    22. if(mCustomToolTip)
    23. mCustomToolTip->hide();
    24. }
    25. return QWidget::event(e);
    26. }
    27.  
    28. void PushButton::mouseMoveEvent( QMouseEvent* e)
    29. {
    30. _mousePoint = e->pos() ;
    31. }
    To copy to clipboard, switch view to plain text mode 
    //.h
    Qt Code:
    1. class CustomToolTip : public QWidget
    2. {
    3. Q_OBJECT
    4. public:
    5. CustomToolTip( QWidget * parent = 0 );
    6. ~CustomToolTip(){}
    7. protected:
    8. void paintEvent ( QPaintEvent * );
    9. private:
    10.  
    11. };
    To copy to clipboard, switch view to plain text mode 

    //.cpp
    Qt Code:
    1. CustomToolTip::CustomToolTip( QWidget * parent )
    2. :QWidget(parent)
    3. {
    4. setWindowFlags(Qt::ToolTip);
    5. resize( 50, 50 );
    6. }
    7.  
    8. void CustomToolTip::paintEvent ( QPaintEvent * )
    9. {
    10. QPainter p(this);
    11. p.fillRect( rect(), Qt::transparent );
    12. p.setBrush(Qt::red);
    13. p.drawEllipse(rect());
    14. }
    To copy to clipboard, switch view to plain text mode 
    //main.cpp
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a(argc, argv);
    4. PushButton* pBtn = new PushButton("OK", &w);
    5. w.resize(400, 500);
    6. pBtn->setGeometry( w.width()/2, w.height()/2, 80, 30 );
    7. w.show();
    8. a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
    9. return a.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

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

    merry (3rd August 2007)

  9. #28
    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 am using 5 buttons on my main window, and for every button it is showing the same tooltip(ellipse) , Is there a way that for every button it shows different tooltip.

    Thanx
    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, 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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.