Results 1 to 19 of 19

Thread: scale painter to fit my widget

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: scale painter to fit my widget

    Thanks , this is what i was looking for.
    but now im facing other problem, which is the size.

    for example,

    I want to draw an ellipce in the same area.

    i want the postion of the ellipce to be affected and to be mapped to viewport area. but i want it to keep the same size i assinge to it.

    for example :

    Painter.drawEllpice(x,y,2,2);
    now when i map it to the viewPort, and when the x,y are really big, you can not see the ellipce at all and as size is mapped as well and beome sooo small.

    so is there a way to can keep the size always the same no matter what x,y is or no matter what viewport i gave.

    Thanks

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

    Default Re: scale painter to fit my widget

    Did you use setWindow?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: scale painter to fit my widget

    yes I did.

    this is wat i did:
    Qrect my rect(x,y,h,w);
    QPoint p(x1,y1);

    painter.setViewPort(widget->rect());
    painter.setwindow(x,y,h,w);


    painter.drawRect(myrect);
    painter.drawEllipce(p,2,2);


    is my rect is small , the ellipce is fine, but if the rect is big and then the ellipce is sooo samll that u cannot see
    i have to set the size of the ellipce so big so i can see it.

    like:
    painter.drawEllipce(p,2000,2000);

    but ofcource then is the window is small the ellipce will be too big.

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

    Default Re: scale painter to fit my widget

    What did you pass as x, y, h and w? (btw. it is w and h and not h and w)
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: scale painter to fit my widget

    i passed the value of my rect:

    for example :

    Qt Code:
    1. QRect myrect(0,0,2000,4000);
    2. QPoint(1000,2000);
    3.  
    4. QRect veiwRect = widget->rect();
    5.  
    6.  
    7. painter.setViewPort(viewRect)
    8. painter.setWindow(myRect);
    9.  
    10. painter.drawRect(myRect);
    To copy to clipboard, switch view to plain text mode 

    I notice something else is that, it will fill the whole widget and it will not use its a coordinates, so even if was the height a way bigger than the width,
    it still show that the width bigger than the height.

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

    Default Re: scale painter to fit my widget

    If you pass such big values then no wonder your ellipse is so small. 2 / 2000 = 0.001; 2 / 4000 = 0.0005 so your ellipse takes 0.1% x 0.05% of the widget area.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: scale painter to fit my widget

    yeah i know, so this is why im asking if there is a way to make the size of the ellipce fixed, because the rect some times have big values and other may have small value.

    so im asking if there is a way to make the ellipce has fixed size and will be showen with same size all the times.

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

    Default Re: scale painter to fit my widget

    Quote Originally Posted by jesse_mark View Post
    yeah i know, so this is why im asking if there is a way to make the size of the ellipce fixed
    Draw the ellipse before you use setWindow() and setViewport() or pass invalid rects to the two to reset them to default before painting the ellipse.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: scale painter to fit my widget

    the issue is that the ellipse position then.
    where the position of the ellipse is related to the rect i draw.
    if i do it before or pass empty rects, the shot will be drawn out side of the visible area of the widget.

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

    Default Re: scale painter to fit my widget

    I'm sorry, I do not understand what you want. Unless you manage to explain it better, I'm afraid I can't help you.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: scale painter to fit my widget

    OK, ill try to explain what im trying to do exactly,

    I have a small widget, lets say it with size of 250, 250.

    I want to draw a rectangle and an ellipse.

    the rect can be really big or small depend on the user input. and the ellipse position as well.
    i want them to be scaled to fit in the widget.

    ps: the ellipse position will be really close to the rect, so it could be beside one of the rect borders or in the middle of the rect.

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

    Default Re: scale painter to fit my widget

    It is still not clear what you want. For me "scaled to fit" means the ellipse and rectangle should be the size of the widget:

    Qt Code:
    1. void Widget::paintEvent(QPaintEvent *pe) {
    2. QPainter p(this);
    3. p.setBrush(Qt::red);
    4. p.drawRect(rect());
    5. p.setBrush(Qt::yellow);
    6. p.drawEllipse(rect());
    7. }
    To copy to clipboard, switch view to plain text mode 

    If you wish to keep the aspect ratio then compare width to height and scale the rectangle to the smaller of the two values.

    Qt Code:
    1. int side = qMin(width(), height());
    2. QRect r(0,0, side, side);
    3. r.moveCenter(rect().center());
    4. p.drawRect(r);
    5. p.drawEllipse(r);
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 5
    Last Post: 21st July 2010, 15:49
  2. Replies: 0
    Last Post: 4th May 2010, 09:45
  3. Scale a widget
    By yagabey in forum Qt Programming
    Replies: 2
    Last Post: 7th December 2008, 13:08
  4. qwtscalewidget: setting scale to the widget..
    By halberdier83 in forum Qwt
    Replies: 3
    Last Post: 4th December 2007, 08:08
  5. My own scale widget in Qwt
    By igrms in forum Qwt
    Replies: 7
    Last Post: 15th June 2006, 21:18

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
  •  
Qt is a trademark of The Qt Company.