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. Limit paint area
QtWS25 Last Chance

Limit paint area

Scheduled Pinned Locked Moved Solved General and Desktop
qpainttranslationviewport
5 Posts 2 Posters 2.2k Views
  • 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.
  • S Offline
    S Offline
    Suths
    wrote on last edited by
    #1

    Hi all,

    I have a widget for which I would like to hand certain areas of the widget's "paint area" of to other classes for drawing. However I would like these other classes to only be able to paint in their provided areas, i.e they have their own local coordinate system. Any ideas on the best way to accomplish something like this?

    Thanks

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      The best was if these other classes was also widgets
      and the master widget simply was a container for these widgets.
      Then each would paint inside its area and not possible to paint outside.

      However, you can send the painter & to some function in X class and let it draw.
      You can use clipping to keep them restricted.
      http://doc.qt.io/qt-5/qpainter.html#clipping

      But its sounds messy unless those other classes are utility classes and do not have any normal painting beside the drawing they do to the master widget.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Suths
        wrote on last edited by
        #3

        I guess I should of given a bit more information here.

        What I actually have is class hierarchy that has a base of QGraphicObject. The idea here is that sections can be added by creating a section class which as you correctly said does not have it's own paint function, but instead receives the masters painter. The master painter however before providing the painter should of set up a new local coordinate system that sets 0,0 top left for example of this sub area.

        Image - just in case the link doesn't work https://postimg.org/image/yxbjdq0c3/

        I think I understand clipping, but i believe i would some how need to limit the window before providing it to the help class.

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          hi
          Maybe you can use
          http://doc.qt.io/qt-5/qpainter.html#translate
          to translate the sub area so sum area start at 0,0 .
          and combined with clipping it could protect the full area somewhat.

          1 Reply Last reply
          2
          • S Offline
            S Offline
            Suths
            wrote on last edited by
            #5

            Thanks for the advice mrjj. I used the translate functions and the save and restore to ensure that each section has a logical coordinate system that makes sense to it.

            1 Reply Last reply
            1

            • Login

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