Can I see the code?
Can I see the code?
Yaa Sure...
QButton.cpp //Subclass of QPushButton
Qt Code:
#include "QButton.h" #include <QEvent> #include <QHelpEvent> { MyToolTipButton1->setText("abc"); } { { if(!mCustomToolTip) //mCustomToolTip = new CustomToolTip(); MyToolTipButton1->show(); e->accept(); return true; } else { if(mCustomToolTip) MyToolTipButton1->hide(); } }To copy to clipboard, switch view to plain text mode
QButton.h
Qt Code:
#ifndef QBUTTON_H #define QBUTTON_H #include <QPushButton> #include <QEvent> #include "CustomToolTip.h" class CustomToolTip; { Q_OBJECT public: public: QPushButton *MyToolTipButton1; protected: public: CustomToolTip *mCustomToolTip; }; #endifTo copy to clipboard, switch view to plain text mode
CustomToolTip.h
Qt Code:
#ifndef CustomToolTip_H #define CustomToolTip_H #include <QToolTip> { Q_OBJECT public: CustomToolTip(); public: void paintEvent() ; }; #endifTo copy to clipboard, switch view to plain text mode
CustomToolTip.cpp
Qt Code:
#include "CustomToolTip.h" #include <QPainter> void CustomToolTip::paintEvent() { p.fillRect(rect(), Qt::transparent ); p.setBrush(Qt::red); p.drawEllipse(rect()); }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
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
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
QToolTip is not a QObject... remove the Q_OBJECT macro...![]()
Current Qt projects : QCodeEdit, RotiDeCode
In this case change the inheritance from QToolTip to QWidget.
And in the constructor of CustomToolTip:
Qt Code:
setWindowFlags(Qt::ToolTip);To copy to clipboard, switch view to plain text mode
Regards
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:
{ if(!mCustomToolTip) mCustomToolTip = new CustomToolTip(this); mCustomToolTip->show(); e->accept(); return true; }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 09:18. Reason: updated contents
Always Believe in Urself![]()
Merry
Pls...Pls............help
Always Believe in Urself![]()
Merry
Firstly, in the CustomToolTip class do this
Qt Code:
{ setWindowFlags(Qt::ToolTip); resize( 50, 50 ); }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.
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:
#include "CustomToolTip.h" #include <QPainter> { setWindowFlags(Qt::ToolTip); resize(50,50); } { p.fillRect(rect(), Qt::transparent ); p.setBrush(Qt::red); p.drawEllipse(rect()); }To copy to clipboard, switch view to plain text mode
QButton.cpp
Qt Code:
#include "QButton.h" #include <QEvent> #include <QHelpEvent> { setMouseTracking(true); FileRecovery->setFocusPolicy(Qt::StrongFocus); } { { if(!mCustomToolTip) mCustomToolTip = new CustomToolTip(0); mCustomToolTip->show(); e->accept(); return true; } else { if(mCustomToolTip) mCustomToolTip->hide(); } }To copy to clipboard, switch view to plain text mode
MainWindow.cpp
Qt Code:
#include "MainWindow.h" #include "QButton.h" #include <QtGui> MainWindow::MainWindow() { button=new MyToolTipButton(0); centralWidget->setFixedSize(500,300); button->FileRecovery->setGeometry(20,20,121,121); button->FileRecovery->setFixedSize(121,121); button->FileRecovery->setToolTip("Hello"); button->RawRecovery->setGeometry(140,20,121,121); button->RawRecovery->setFixedSize(121,121); controlsLayout->addStretch(1); lineLayout->addSpacing(1); centralLayout->addLayout(controlsLayout); centralLayout->addWidget(button->FileRecovery, 1); centralLayout->addWidget(button->RawRecovery, 0); centralLayout->addSpacing(1); centralLayout->addLayout(lineLayout); centralWidget->setLayout(centralLayout); setCentralWidget(centralWidget); button->FileRecovery->installEventFilter(this); }To copy to clipboard, switch view to plain text mode
Regards
Always Believe in Urself![]()
Merry
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
//.cppQt Code:
{ Q_OBJECT public: ~PushButton(){} protected: private: CustomToolTip *mCustomToolTip; QPoint _mousePoint; };To copy to clipboard, switch view to plain text mode
//.hQt Code:
{ setText(text); mCustomToolTip = 0; setMouseTracking(true); } { { if(!mCustomToolTip) mCustomToolTip = new CustomToolTip( this); mCustomToolTip->show(); e->accept(); return true; } else { if(mCustomToolTip) mCustomToolTip->hide(); } } { _mousePoint = e->pos() ; }To copy to clipboard, switch view to plain text mode
Qt Code:
{ Q_OBJECT public: ~CustomToolTip(){} protected: private: };To copy to clipboard, switch view to plain text mode
//.cpp
//main.cppQt Code:
{ setWindowFlags(Qt::ToolTip); resize( 50, 50 ); } { p.fillRect( rect(), Qt::transparent ); p.setBrush(Qt::red); p.drawEllipse(rect()); }To copy to clipboard, switch view to plain text mode
Qt Code:
int main(int argc, char *argv[]) { QMainWindow w; PushButton* pBtn = new PushButton("OK", &w); w.resize(400, 500); pBtn->setGeometry( w.width()/2, w.height()/2, 80, 30 ); w.show(); a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit())); return a.exec(); }To copy to clipboard, switch view to plain text mode
merry (3rd August 2007)
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
Bookmarks