Results 1 to 3 of 3

Thread: Opacity QPainter in thread Qt4.7

  1. #1
    Join Date
    Apr 2015
    Posts
    3
    Thanks
    3

    Default Opacity QPainter in thread Qt4.7

    Hi,

    Qt 4.7. Outside the thread of code works fine:

    Qt Code:
    1. QImage IMG;
    2. QPainter PAINTER;
    3. QPen PEN;
    4.  
    5. IMG.load("img.jpg");
    6. PAINTER.begin(&IMG);
    7.  
    8. PEN.setColor("#ff0000");
    9. PAINTER.setOpacity(0.30);
    10. PAINTER.setPen(PEN);
    11. PAINTER.drawText( 20, 20, "Test");
    To copy to clipboard, switch view to plain text mode 

    But when put into the thread drawText crash:
    Qt Code:
    1. QObject::killTimers: timers cannot be stopped from another thread
    To copy to clipboard, switch view to plain text mode 

    If remove the method:
    Qt Code:
    1. PAINTER.setOpacity(0.30);
    To copy to clipboard, switch view to plain text mode 
    or send it to 0 or 1 , starts to work fine.

    Tried to change it to:
    Qt Code:
    1. QColor clr = QColor("#ff0000");
    2. PEN.setColor( QColor( clr.red(), clr.green(), clr.blue(), 254 ) );
    To copy to clipboard, switch view to plain text mode 
    but not help

    Any ideas?
    Thanks in advance)

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Opacity QPainter in thread Qt4.7

    Maybe you could show how you put that into a thread.

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    cupersuper (10th April 2015)

  4. #3
    Join Date
    Apr 2015
    Posts
    3
    Thanks
    3

    Default Re: Opacity QPainter in thread Qt4.7

    mythread.cpp
    Qt Code:
    1. MyThread::MyThread(QObject *parent) :
    2. QThread(parent)
    3. {
    4. }
    5.  
    6. void MyThread::run()
    7. {
    8. QImage IMG;
    9. QPainter PAINTER;
    10. QPen PEN;
    11. IMG.load("img.jpg");
    12. PAINTER.begin(&IMG);
    13.  
    14.  
    15. PEN.setColor("#ff0000");
    16. PAINTER.setOpacity(0.30); //This string
    17. PAINTER.setPen(PEN);
    18. PAINTER.drawText( 20, 20, "Test"); //crash this method
    19. IMG.save("done.jpg");
    20. }
    To copy to clipboard, switch view to plain text mode 
    mainwindow.cpp
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5. ui->setupUi(this);
    6. MThread = new MyThread();
    7. MThread->start();
    8. }
    To copy to clipboard, switch view to plain text mode 
    This code don't work

    _______________________________________
    mainwindow.cpp
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5. ui->setupUi(this);
    6.  
    7. QImage IMG;
    8. QPainter PAINTER;
    9. QPen PEN;
    10. IMG.load("img.jpg");
    11. PAINTER.begin(&IMG);
    12.  
    13.  
    14. PEN.setColor("#ff0000");
    15. PAINTER.setOpacity(0.30);
    16. PAINTER.setPen(PEN);
    17. PAINTER.drawText( 20, 20, "Test");
    18. IMG.save("done.jpg");
    19. }
    To copy to clipboard, switch view to plain text mode 
    This code works fine
    Last edited by cupersuper; 10th April 2015 at 07:13.

Similar Threads

  1. Qt/Android: Use QPainter in secondary thread.
    By kiozen in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 27th January 2014, 14:02
  2. change the opacity
    By askatuak in forum Qt Quick
    Replies: 1
    Last Post: 18th September 2013, 17:20
  3. Replies: 9
    Last Post: 13th September 2011, 03:04
  4. QDialog with QPainter in new thread
    By grucha in forum Qt Programming
    Replies: 0
    Last Post: 21st November 2009, 23:17
  5. Window Opacity
    By chethana in forum Qt Programming
    Replies: 1
    Last Post: 10th October 2007, 11:45

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.