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. How to use QPainter in sub-thread ?
Forum Update on Monday, May 27th 2025

How to use QPainter in sub-thread ?

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 1.7k 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.
  • M Offline
    M Offline
    MartinChan 0
    wrote on last edited by
    #1

    I have a question about QPainter. As we know :

    1. QPainter could only be used in a paintEvent();
    2. A paintEvent() is a over-ride function that only a QWidget has.
    3. A QWidget is a UI member, and qt's ui could only be in main thread.

    So , does that mean u could only use QPainter in main thread ?? How could I draw a QImage in backstage ?

    jsulmJ 1 Reply Last reply
    0
    • M MartinChan 0

      I have a question about QPainter. As we know :

      1. QPainter could only be used in a paintEvent();
      2. A paintEvent() is a over-ride function that only a QWidget has.
      3. A QWidget is a UI member, and qt's ui could only be in main thread.

      So , does that mean u could only use QPainter in main thread ?? How could I draw a QImage in backstage ?

      jsulmJ Online
      jsulmJ Online
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @MartinChan-0 said in How to use QPainter in sub-thread ?:

      QPainter could only be used in a paintEvent();

      This is a wrong assumption. See documentation (http://doc.qt.io/qt-5/qpainter.html):
      "Warning: When the paintdevice is a widget, QPainter can only be used inside a paintEvent() function or in a function called by paintEvent()."

      If you want to paint on a QImage it should work in a thread.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2

      • Login

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