Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. QPainter in PyQt
Qt 6.11 is out! See what's new in the release blog

QPainter in PyQt

Scheduled Pinned Locked Moved Language Bindings
6 Posts 3 Posters 8.6k 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.
  • L Offline
    L Offline
    luishengjie
    wrote on last edited by
    #1

    Hi guys, I kinda new with ptqt and seem to have the following error when I try to create a simple QPaint program. Does anyone know how can I "active" my Painter? Help is much appreciated. Thanks you in advance.
    QPainter::setRenderHint: Painter must be active to set rendering hints
    QPainter::setPen: Painter not active

    def paintEvent(self, event = None):
    paint = QPainter()
    paint.setRenderHint(QPainter.Antialiasing)
    paint.setPen(QtGui.QPen(QtGui.QColor(Qt.green)))
    paint.drawEllipse(300,300,70,70)

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tilsitt
      wrote on last edited by
      #2

      Hi,

      To be active, your painter must be connected to a device, either by giving it as argument during construction or by calling QPainter::begin().

      1 Reply Last reply
      0
      • L Offline
        L Offline
        luishengjie
        wrote on last edited by
        #3

        def paintEvent(self, event = None):
        paint = QPainter()
        paint.begin()
        paint.setRenderHint(QPainter.Antialiasing)
        paint.setPen(QtGui.QPen(QtGui.QColor(Qt.green)))
        paint.drawEllipse(300,300,70,70)
        paint.end()

        I initially had the paint.begin() statement however when i implement that statement I would have the following error:
        TypeError: QPainter.begin(QPaintDevice): not enough arguments

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tilsitt
          wrote on last edited by
          #4

          The error is giving you the answer: begin() takes a QPaintDevice (e.g. a widget) as argument.

          1 Reply Last reply
          0
          • L Offline
            L Offline
            luishengjie
            wrote on last edited by
            #5

            What is considered as a QPaintEvent argument?

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

              Hi,

              My PyQt is a bit rusted but IIRC you need something like:

              @
              paint = QPainter(self)
              @

              Otherwise you are trying to paint on nothing so it won't work.

              Hope it helps

              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

              • Login

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