Results 1 to 3 of 3

Thread: QPainter clipped?

  1. #1
    Join Date
    Aug 2006
    Location
    troy, new york
    Posts
    24
    Thanks
    4
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default QPainter clipped?

    hi,
    i subclassed QPushButton for a widget i'm using and i'm having problems getting the whole button to show. when the button is drawn the "ends" are missing. i've tried changing the scale and translation with no luck. i have looked at the docs trying to figure which if i'm clipping by mistake in orientation. here's the code with no geometry set:

    void pb: : paintEvent(QPaintEvent *)
    {
    QStyleOptionButton option;
    option.initFrom(this);
    QStylePainter p(this);
    p.scale(1.0, 8.50);
    p.translate(0,50);
    p.rotate(-90);
    p.drawControl(QStyle::CE_PushButton, option);
    }


    thanks in advance.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QPainter clipped?

    A widget cannot draw outside it's boundaries.

    Since you rotate 90 degrees, you must also swap the width and height:
    Qt Code:
    1. QSize s = option.rect.size(); // rect has been initialized in QStyleOption::initFrom()
    2. s.transpose(); // swaps width and height
    3. option.rect.setSize(s);
    To copy to clipboard, switch view to plain text mode 

    ..and you must translate the coordinate system to match rotation
    Qt Code:
    1. p.rotate(-90);
    2. p.translate(-height(), 0);
    To copy to clipboard, switch view to plain text mode 

    You might also want to take a look at QPushButtonPrivate::getStyleOption(). You need a properly initialized QStyleOptionButton to get the button drawn correctly.
    J-P Nurmi

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QPainter clipped?

    QtCentre Wiki: OrientationButton
    J-P Nurmi

Similar Threads

  1. QPainter and QImage
    By beerkg in forum Newbie
    Replies: 3
    Last Post: 7th September 2006, 14:48
  2. QPainter in console apps?
    By Funklord in forum Qt Programming
    Replies: 2
    Last Post: 18th April 2006, 14:03
  3. Replies: 7
    Last Post: 20th March 2006, 20:03
  4. 2 Questions about QPainter
    By SkripT in forum Qt Programming
    Replies: 12
    Last Post: 22nd February 2006, 15:08
  5. passing a QPainter object to widgets
    By vratojr in forum Qt Programming
    Replies: 9
    Last Post: 11th January 2006, 15:27

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.