
Originally Posted by
impeteperry
The use of the "function/accelerator keys" for program control rather then the mouse is part and parcel of what I am trying to develop, right or wrong.
But that's not the issue here. If you have other things working, adding accelerators is trivial. If something doesn't work, it means the problem is elsewhere.
My problem is "I can show a "Help widget" on a painter by pressing a function key, but I can't delete it by pressing a function key". My Question is "what code to I need to add to my "help Widget to correct this problem"?
You need to implement a paint event correctly, so that it takes into consideration the help widget. I'd add a property holding the help text to show and when the text is empty, hide the help and otherwise render the text. Something like:
class MyClass: public ... {
Q_OBJECT
Q_PROPERTY(QString helpText READ helpText WRITE setHelpText
) public:
//...
const QString &helpText
() const { return m_helpText;
} public slots:
void setHelpText
(const QString &txt
) { if(txt==m_helpText) return;
m_helpText = txt;
update();
}
void clearHelpText
() { setHelpText
(QString::null);
} protected:
void paintEvent(...){
//...
if(!m_helpText.isEmpty()){
p.save();
//...
p.drawRect(...);
p.drawText(...);
p.restore();
}
}
};
class MyClass: public ... {
Q_OBJECT
Q_PROPERTY(QString helpText READ helpText WRITE setHelpText)
public:
//...
const QString &helpText() const { return m_helpText; }
public slots:
void setHelpText(const QString &txt) {
if(txt==m_helpText) return;
m_helpText = txt;
update();
}
void clearHelpText() { setHelpText(QString::null); }
protected:
void paintEvent(...){
QPainter p(this);
//...
if(!m_helpText.isEmpty()){
p.save();
//...
p.drawRect(...);
p.drawText(...);
p.restore();
}
}
};
To copy to clipboard, switch view to plain text mode
Actually I'd use QCanvas or QGraphicsView...
Bookmarks