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. paintEvent() vs render()
Forum Updated to NodeBB v4.3 + New Features

paintEvent() vs render()

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 700 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.
  • R Offline
    R Offline
    Ross Boylan
    wrote on last edited by
    #1

    I've seen examples that mplement the painting logic in paintEvent(), and others that do it in render(). Which to choose? Perhaps a better question is what are the consideration in using one or the other, or even both?

    Both methods sound pretty similar from the descriptions. And both are overloaded with various call signatures.

    I'll be doing this from Python, with Qt5. Which I guess renders the issue of different function signatures somewhat moot.

    Thanks

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

      Hi,

      The paintEvent method is to draw your widget. The render method is to paint your widget onto a specific target.

      The former is the one that most people implement for their custom UIs. The later can be used for example when you want to render your widget when printing it.

      [edit: Fixed wrong wording SGaist]

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • R Offline
        R Offline
        Ross Boylan
        wrote on last edited by
        #3

        Thanks for your answer. I think I'm still missing something; I thought the painting process was device independent, so that putting an image on the screen and putting it on the printer were just a matter of swapping PaintDevice's, assuming one's painting logic adjusts for pixel density variation. But it sounds as if you're saying that painting the screen goes through different code in the QWidget than painting the printer.

        I realize painting to the screen is potentially more dynamic as parts of the window are covered and uncovered.

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

          By default paintEvent does nothing.

          render is used to obtain the content of a widget. I just realized that it's also not virtual and thus you can't overload it.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          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