Results 1 to 4 of 4

Thread: Repaint Event

  1. #1
    Join Date
    Feb 2006
    Posts
    42
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Repaint Event

    Hi all,

    I have a problem with respect to paint event, I have a class ToolButton derived from QToolButton, here is its paintEvent implementation. Even though I set the instance of ToolButton as, setGeometry(10,10,60,60), I get very less reading for width and height in the paint Event, am I doing anything wrong here??

    void ToolButton:aintEvent(QPaintEvent *e)
    {
    int co_x = (int)x() - (width() / 2);
    int co_y = (int)y() - (height() / 2);

    QPainter painter(this);
    QPixmap mypix;
    mypix.load(":images/f1u7.png");
    mypix=mypix.scaled (width(),height(),Qt::IgnoreAspectRatio);
    cout<<co_x<<","<<co_y<<","<<width()<<","<<height() <<endl;
    painter.drawPixmap(co_x,co_y,width(),height(), mypix);
    }

    Thanks in advance,
    Seema Rao

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Repaint Event

    Can you show the class declaration and constructor? BTW. It doesn't make much sense to inherit QToolButton if you don't use its paintEvent. Maybe you should inherit QAbstractButton instead?

  3. #3
    Join Date
    Feb 2006
    Posts
    42
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Repaint Event

    #include <QToolButton>

    class ToolButton: public QToolButton
    {

    public:
    ToolButton(QWidget *parent=0);
    private:

    QString str1;

    protected:
    void paintEvent(QPaintEvent *e);
    };
    //here is the constructor

    ToolButton::ToolButton(QWidget *parent): QToolButton(parent){}

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Repaint Event

    And what's wrong exactly? And why can't you use QToolButton and its setIcon() method instead of subclassing?

Similar Threads

  1. Replies: 4
    Last Post: 19th February 2009, 11:10
  2. Custom event gets not propagated to the top level widget
    By nightghost in forum Qt Programming
    Replies: 0
    Last Post: 29th January 2009, 09:06
  3. Event propagation direction
    By spraff in forum Qt Programming
    Replies: 0
    Last Post: 6th December 2008, 21:03
  4. Qt event queue overloading?
    By gct in forum Qt Programming
    Replies: 3
    Last Post: 17th March 2008, 18:39
  5. Workload in a QThread blocks main application's event loop ?
    By 0xBulbizarre in forum Qt Programming
    Replies: 14
    Last Post: 9th April 2006, 21:55

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.