Qt-interest Archive, July 2007
paintEvent test code to change font weight - fails !
Message 1 in thread
I am trying to 'overload' QPushButton so that - in this test case -
QPushButtons text would be in bold instead of its default normal
however it does not work. My test code is ...
class MyPushButton : public QPushButton
{
public:
MyPushButton(QWidget * parent)
: QPushButton(parent) {}
void paintEvent(QPaintEvent *event)
{
QPainter p(this);
QFont f = p.font();
f.setWeight(QFont::Bold);
p.setFont(f);
QPushButton::paintEvent(event);
}
};
Can anyone tell me where I am going wrong ?
Many thanks
Dave
--
[ signature omitted ]
Message 2 in thread
On 7/7/07, dave selby <dave6502@xxxxxxxxxxxxxx> wrote:
> I am trying to 'overload' QPushButton so that - in this test case -
> QPushButtons text would be in bold instead of its default normal
> however it does not work. My test code is ...
>
> class MyPushButton : public QPushButton
> {
> public:
> MyPushButton(QWidget * parent)
> : QPushButton(parent) {}
>
> void paintEvent(QPaintEvent *event)
> {
> QPainter p(this);
>
> QFont f = p.font();
> f.setWeight(QFont::Bold);
> p.setFont(f);
>
> QPushButton::paintEvent(event);
>
> }
> };
>
> Can anyone tell me where I am going wrong ?
Constructing a QPainter and setting the font on it doesn't modify the
QPaintEvent* passed to QPushButton::paintEvent(), so the drawing is
unmodified. One tactic that would work is implementing a proxy style,
although it might not be the simplest way.
--
[ signature omitted ]
Message 3 in thread
Why not just set the font on the pushbutton itself?
Ie
MyPushButton( QWidget * parent )
{
QFont f = font();
f.setWeight( Bold )
setFont( f ):
}
> -----Original Message-----
> From: dave selby [mailto:dave6502@xxxxxxxxxxxxxx]
> Sent: Saturday, July 07, 2007 3:54 PM
> To: Qt list
> Subject: paintEvent test code to change font weight - fails !
>
> I am trying to 'overload' QPushButton so that - in this test case -
> QPushButtons text would be in bold instead of its default normal
> however it does not work. My test code is ...
>
> class MyPushButton : public QPushButton
> {
> public:
> MyPushButton(QWidget * parent)
> : QPushButton(parent) {}
>
> void paintEvent(QPaintEvent *event)
> {
> QPainter p(this);
>
> QFont f = p.font();
> f.setWeight(QFont::Bold);
> p.setFont(f);
>
> QPushButton::paintEvent(event);
>
> }
> };
>
> Can anyone tell me where I am going wrong ?
>
> Many thanks
>
> Dave
>
>
>
> --
>
> Please avoid sending me Word or PowerPoint attachments.
> See http://www.gnu.org/philosophy/no-word-attachments.html
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
--
[ signature omitted ]