Results 1 to 3 of 3

Thread: QPointF - draw only 30% of window

  1. #1
    Join Date
    May 2017
    Posts
    13
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default QPointF - draw only 30% of window

    Hello,
    I wonder. "Width" of QWidget is in what resolution?
    I mean:

    Qt Code:
    1. ui::QWidget::width()
    To copy to clipboard, switch view to plain text mode 

    It will return value in what units?

    I have code that dinamically draws (by QPainter) QPointF (many of them).
    And for my horizontal coordinate I have that code:

    Qt Code:
    1. QPointF point;
    2.  
    3. for(int i=1; i<something; i++)
    4. {
    5. point.setX(i);
    6. }
    To copy to clipboard, switch view to plain text mode 

    And my aim is to use "something" as a resolution. So for example: no matter how big is "something", my points always fill evenly for example 30% of my widget. But that doesn't work:
    Qt Code:
    1. ui::QWidget::width() * 0.3
    To copy to clipboard, switch view to plain text mode 

    Because QPointF is in different units than widget width.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QPointF - draw only 30% of window

    A QWidget's width and height are always in pixel units. The mapping from QPainter coordinates to QWidget coordinates is one-to-one in pixels unless you have applied a scaling transformation to the QPainter.

    Your code makes no sense. The for() loop repeatedly sets the x value, and when it exits, point.x() will always have the last value of i (that is, "something" - 1). And if "something" is capped at 30% of the width (converted to an integer, since "i" is an int), the last x that is assigned will be 30% of the width.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    May 2017
    Posts
    13
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: QPointF - draw only 30% of window

    OK, I'm sorry, I was wrong in some way, I don't understand why, because now everything works fine for me.
    And great thanks for your reply

Similar Threads

  1. allow user to draw n sided polygons in an open window
    By bruceqtbeginner in forum Newbie
    Replies: 1
    Last Post: 8th June 2016, 20:10
  2. Draw UI on the X11 window
    By iddqd in forum Qt Programming
    Replies: 0
    Last Post: 16th November 2011, 06:41
  3. Replies: 2
    Last Post: 27th June 2011, 14:44
  4. Replies: 1
    Last Post: 2nd May 2011, 11:12
  5. Replies: 4
    Last Post: 21st February 2011, 15:28

Tags for this Thread

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.