Results 1 to 4 of 4

Thread: [PARTIALLY SOLVED] Error drawing?

  1. #1
    Join Date
    Jun 2014
    Qt products
    MacOS X Unix/X11 Windows

    Angry [PARTIALLY SOLVED] Error drawing?

    EDIT: For anyone getting this kind of error, override the paintEvent(QPaintEvent*) method..
    EDIT 2: The painting is happening as many times as something is drawn in the screen, aint there a way for this to happen only once without adding some bool in there?
    Hey all, I've got a project going where I'm trying to learn about clipping regions and painting.
    However, I'm stuck.
    The code presented below shows the clipped widget. Now, when I try to paint a red line on the borders of the clipped widget, it will, no error thrown, not even try to paint, or am I missing something?

    Qt Code:
    1. Cargador::Cargador(QWidget *parent) : QWidget(parent,Qt::FramelessWindowHint), ui(new Ui::Cargador) {
    2. ui->setupUi(this);
    3. resize(500,255);
    4. QRegion esquina;
    5. QRegion circulo;
    6. QRegion region(0,0,width(),height(),QRegion::Rectangle);
    8. circulo = QRegion(0,0,50,50,QRegion::Ellipse); // Circulo hardcodeado
    9. esquina = QRegion(0,0,25,25,QRegion::Rectangle); // Cuadrado de un cuarto del circulo
    10. region = region.subtracted(esquina.subtracted(circulo));
    12. circulo = QRegion(width()-50,height()-50,50,50,QRegion::Ellipse);
    13. esquina = QRegion(width()-25,height()-25,25,25,QRegion::Rectangle);
    14. region = region.subtracted(esquina.subtracted(circulo));
    15. setMask(region);
    16. QPixmap logo(":/Cargador/Imagenes/Logo.png",0,Qt::AutoColor);
    17. // qDebug() << logo;
    18. ui->lblLogo->setPixmap(logo);
    19. ui->lblLogo->show();
    20. // Labels transparentes
    21. ui->label->setAttribute(Qt::WA_TranslucentBackground);
    22. ui->label_2->setAttribute(Qt::WA_TranslucentBackground);
    23. ui->lblCargando->setAttribute(Qt::WA_TranslucentBackground);
    24. ui->lblLogo->setAttribute(Qt::WA_TranslucentBackground);
    25. // Borde en negro.
    26. QPainter decorador(this);
    27. //QPolygon poligono;
    28. QPen linea;
    29. zona.addRegion(region);
    30. linea.setWidth(8);
    31. linea.setColor(Qt::red);
    32. decorador.setPen(linea);
    34. decorador.drawPath(zona);
    38. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by QNewbie; 7th June 2014 at 03:06. Reason: Not that solved

  2. #2
    Join Date
    Mar 2009
    Brisbane, Australia
    Thanked 1,588 Times in 1,517 Posts
    Qt products
    Qt4 Qt5
    Unix/X11 Windows
    Wiki edits

    Default Re: [PARTIALLY SOLVED] Error drawing?

    The paintEvent() code should render the entire widget or just the region passed in with the event parameter. How you do that in an optimal fashion is entirely up to you and your application characteristics. The paint event code is called as often as required to keep the display current, for example every time the widget is resized, partly hidden, shown or exposed after being obscured. Qt already takes some actions to merge successive events that might trigger repaint into a single call.

    Painting in the constructor, i.e. before the widget is visible, will simply be obliterated the first time the paint event fires after you call show() (if it draws anything at all).

  3. #3
    Join Date
    Jun 2014
    Qt products
    MacOS X Unix/X11 Windows

    Default Re: [PARTIALLY SOLVED] Error drawing?

    You're right, that's why I moved the code to the overriden paintEvent() method.
    Yet it paints something weird, the code I added to the function was:
    Qt Code:
    1. void Cargador::paintEvent(QPaintEvent *evento) {
    2. QPainter decorador(this);
    3. QPen linea;
    4. linea.setWidth(3);
    5. decorador.setPen(linea);
    6. zona.addRegion(region);
    7. decorador.drawPath(zona);
    8. }
    To copy to clipboard, switch view to plain text mode 

    However instead of drawing one line, I'm greated with this:

  4. #4
    Join Date
    Jan 2006
    Warsaw, Poland
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits

    Default Re: [PARTIALLY SOLVED] Error drawing?

    Could you start again from telling us what is the intended behaviour and what is the current behaviour you are experiencing? The image you posted doesn't really explain the problem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.

Similar Threads

  1. arm + drawing
    By raghavendraningoji in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 31st December 2011, 16:57
  2. Exported PDF Drawing Error in Adobe Reader
    By BettaUseYoNikes in forum Qwt
    Replies: 0
    Last Post: 15th November 2011, 16:58
  3. Qt Drawing
    By Talguy in forum Newbie
    Replies: 4
    Last Post: 12th January 2011, 04:14
  4. error for drawing a line on mainwindow.
    By sujan.dasmahapatra in forum Qt Programming
    Replies: 1
    Last Post: 6th February 2009, 07:15
  5. Drawing an arc.
    By munna in forum Qt Programming
    Replies: 6
    Last Post: 13th June 2006, 05:36


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.