Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Resize Paintevent (fit to widget)
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Resize Paintevent (fit to widget)

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MrNoway
    wrote on last edited by
    #1

    I draw two rects like this.
    Its working but I want the rects to scale when my widget is getting bigger and shrink when my widget is getting smaller.

    How can I do this.
    @

    void Lines::paintEvent(QPaintEvent *e)
    {
    QPainter qp(this);
    QPen pen (Qt::blue, 2, Qt::SolidLine);
    qp.setPen(pen);
    qp.drawRect(100,100,100,100);

    QPainter pp(this);
    QPen pen2(Qt::green, 2, Qt::SolidLine);
    pp.setPen(pen2);
    pp.drawRect(200,200,100,100);
    }@

    Whats the best way to do this?

    thanks

    1 Reply Last reply
    0
    • _ Offline
      _ Offline
      _rmn
      wrote on last edited by
      #2

      I think sizes of your rects should refers to size of widget, for example:
      @
      const int currentWidth = width();
      const int currentHeight = height();
      qp.drawRect(currentWidth * 0.1, currentHeight * 0.1, currentWidth * 0.5, currentHeight * 0.5);
      @

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MrNoway
        wrote on last edited by
        #3

        yai! its working, thanks,

        can you also provide a little function for example like this

        if widget is resized

        {do soemthing...}

        € No need anymore, I didnt know, it could be any variable, so I simply created currentWidth and currentWidth2
        and making a compare (currentWidth2!=currentWidth)

        gonna mark it as solved

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved