Results 1 to 19 of 19

Thread: Qt GraphicsView stop getting paint event

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Exclamation Qt GraphicsView stop getting paint event

    Hello,

    I am working with QGraphicsView and QGraphicsScene for drawing of QPixmap data on QGraphicsItem.
    What i am doing is start a QTimer on each timeout of QTimer i draw data on QPixmap via QtConcurrent.

    Qt Code:
    1. QtConcurrent::run(this, &LinePlotter::plotDataOnImage);
    To copy to clipboard, switch view to plain text mode 

    On plotDataOnImage i call update() after drawing on QPixmap.
    It works fine but unfortunatly my QGraphicsView and QGraphicsScene stop getting paint events.
    but when i click on window it repaint again but it does not repaint on call of update() method.

    customizations for QGraphicsView i have made are:
    Qt Code:
    1. setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    2. setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    3.  
    4. setRenderHints(QPainter::HighQualityAntialiasing | QPainter::SmoothPixmapTransform | QPainter::TextAntialiasing);
    5.  
    6. setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
    7.  
    8. setCacheMode(QGraphicsView::CacheNone);
    9.  
    10. setOptimizationFlags(QGraphicsView::DontAdjustForAntialiasing
    11. | QGraphicsView::DontClipPainter
    12. | QGraphicsView::IndirectPainting);
    To copy to clipboard, switch view to plain text mode 

    I have never got this kind of problem before but i dont know why my view not get its paint event properly.
    any idea about the problem?


    -----------------------------------------------
    There is something i have seen i just start my application and keep it opened without any mouse interaction or any other kind of interactions.
    Then i start my stop watch and checks the log.

    It also got stop painting(stop getting events) when keeping in background (rarely occured)...
    What is the issue?
    I am using Cent OS 6.4
    Qt 5.0

    Please tell me what is the issue?
    Last edited by karankumar1609; 30th July 2013 at 16:17.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt GraphicsView stop getting paint event

    QPixmap cannot be used from threads other than the GUI thread.
    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.


  3. #3
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Qt GraphicsView stop getting paint event

    i have changed my function to drawing on QImage and then i send it a signal
    Qt Code:
    1. signals:
    2. void drawingFinished(const QImage&);
    To copy to clipboard, switch view to plain text mode 

    but the same problem occured.
    the problem will not occur if i direct call that function.
    Somehow it stop getting paint events when i use threads.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt GraphicsView stop getting paint event

    Show your exact code related to this call and tell us why you expect a paint event (i.e. where you call update() or sth).
    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.


  5. #5
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Qt GraphicsView stop getting paint event

    here is my run method implementation of QThread
    Qt Code:
    1. void LinePlotter::run()
    2. {
    3. QTime timeSpan;
    4. timeSpan.start();
    5.  
    6. forever {
    7. const QRectF& visibleRectL = visibleRect();
    8.  
    9. qDebug() << "Timer Out : " << visibleRectL;
    10.  
    11. // *pix = pix->scaled(::max(visibleRectL.width(), 1.0), ::max(visibleRectL.height(), 1.0));
    12. QImage image(visibleRectL.size().toSize(), QImage::Format_ARGB32);
    13.  
    14. QPainter paint;
    15.  
    16. paint.begin(&image);
    17. paint.setRenderHint(QPainter::SmoothPixmapTransform, true);
    18. paint.setBrush(QBrush(Qt::black));
    19. paint.setClipRect(visibleRectL);
    20. paint.drawRect(0, 0, visibleRectL.width(), visibleRectL.height());
    21.  
    22. const qreal& horizontalPP = horizontalPaddingPixel();
    23. const qreal& verticalPP = verticalPaddingPixel();
    24. const qreal& zoomFactorInverse = 1 / zoomFactor();
    25. const qreal& frontL = front();
    26. const qreal &gridY0 = 0, &gridY1 = visibleRectL.height();
    27. const double& height = (this->boundingRect().height() - (2* verticalPP));
    28. const double& xFactor = zoomFactor(), xPadding = + horizontalPP - ::qCeil(frontL);
    29. int startPoint = (frontL * zoomFactorInverse) - (horizontalPP * zoomFactorInverse);
    30. int xPos = mappingLine().x1();
    31. uint mapperWidth = mapper()->size().width();
    32. uint date = 00000000, time = 0000;
    33. QVariantList points;
    34.  
    35. const QVector<PlotData*>& plotDataVector = plotData();
    36.  
    37. if(startPoint < 0)
    38. startPoint = 0;
    39. int endPoint = startPoint + (visibleRectL.width() * zoomFactorInverse) + 5;
    40.  
    41.  
    42. foreach (PlotData* plotDataValue, plotDataVector) {
    43. // Each vector contains the data of one day
    44. const std::vector<ID_Element> &ID = plotDataValue->ID();
    45.  
    46. int IDIndex = 0;
    47. foreach (const ID_Element& idElement, ID) {
    48. int j = 0;
    49. const KAxisRange& yRange = plotDataValue->yRange(IDIndex);
    50. const double yFactor = 1.f / (double(yRange.max() - yRange.min()) / height);
    51.  
    52. if(endPoint > plotDataValue->totalPixel())
    53. endPoint = plotDataValue->totalPixel();
    54.  
    55. const std::vector<Date_Element>& dateElement = idElement.ID_vector;
    56. int timeSize = dateElement.front().Time_Vector.size();
    57. qreal min = 0, max = 0;
    58. bool init = true;
    59.  
    60. foreach (const Date_Element& dateData, dateElement) {
    61.  
    62. if((j + timeSize) < startPoint) {
    63. j += timeSize;
    64. } else {
    65. const std::vector<Time_Element>& timeElement = dateData.Time_Vector;
    66. QPolygonF LineToDraw;
    67. QVector<QLineF> gridLines, halfGridLines;
    68.  
    69. foreach (const Time_Element& timeData, timeElement) {
    70. if(j >= startPoint &&
    71. j <= endPoint) {
    72. // value contains some data in it
    73. const std::vector<float>& value = timeData.Value;
    74.  
    75. qreal x = j;
    76. x = (x * xFactor) + xPadding;
    77.  
    78. if(value.size() > 0) {
    79. qreal y = value[0] - yRange.min();
    80. y = height - (y * yFactor) + verticalPP;
    81. LineToDraw << QPointF(x, y);
    82.  
    83. if(j == xPos) {
    84. // value contains some data in it
    85. date = dateData.Date;
    86. time = timeData.Time;
    87.  
    88. QVariantMap mapVal;
    89. mapVal.insert("color", plotDataValue->IDColor(IDIndex));
    90. mapVal.insert("value", QString::number(value[0]));
    91.  
    92. points.append(mapVal);
    93. }
    94.  
    95. if(init) {
    96. init = false;
    97. min = value[0];
    98. max = min;
    99. } else {
    100. qreal range = value[0];
    101.  
    102. if(min > range)
    103. min = range;
    104.  
    105. if(max < range)
    106. max = range;
    107. }
    108. }
    109.  
    110. {
    111. // Draw Grid
    112. if(timeData.Time % 100 == 0)
    113. gridLines << QLineF(QPointF(x, gridY0), QPointF(x, gridY1));
    114. else if((timeData.Time % 100) % 15 == 0)
    115. halfGridLines << QLineF(QPointF(x, gridY0), QPointF(x, gridY1));
    116. }
    117.  
    118. } else if(j > endPoint) {
    119. break;
    120. }
    121. ++j;
    122. }
    123.  
    124. /// Draw graph on pixmap
    125. if(!LineToDraw.isEmpty()) {
    126. paint.setPen(plotDataValue->IDColor(IDIndex));
    127. paint.drawPolyline(LineToDraw);
    128. }
    129.  
    130. {
    131. paint.setPen(QPen(QBrush(Qt::red), 3));
    132. paint.drawLines(gridLines);
    133. }
    134.  
    135. {
    136. paint.setPen(QPen(QBrush(Qt::gray), 1, Qt::DotLine));
    137. paint.drawLines(halfGridLines);
    138. }
    139. }
    140. }
    141.  
    142. // Update the grapg again for new range series
    143. if(yRange.min() != min ||
    144. yRange.max() != max) {
    145. plotDataValue->setYRange(KAxisRange(min, max), IDIndex);
    146. emit rangeChanged(min, max, IDIndex);
    147. // update();
    148. }
    149. ++IDIndex; // increase the ID index number
    150. }
    151. }
    152.  
    153. // Draw pixmap with graph
    154. // Draw mapper line and set mapper position
    155. {
    156. paint.setPen(QPen(QBrush(Qt::green), 1));
    157. paint.setOpacity(1.0);
    158.  
    159. // insert date time
    160. {
    161. QString dateString = QDateTime::fromString(QString::number(date), "yyyyMMdd").toString("yyyy-MM-dd");
    162. QString timeString = QTime::fromString(QString::number(time), "hhmm").toString("hh:mm");
    163.  
    164. QVariantMap dateTimeMap;
    165. dateTimeMap.insert("date", dateString);
    166. dateTimeMap.insert("time", timeString);
    167.  
    168. points.append(dateTimeMap);
    169. }
    170.  
    171. // Draw mapper line
    172. {
    173. xPos = (xPos * zoomFactor()) + xPadding;
    174. const QLineF &lineToDraw = QLineF(QPointF(xPos, 0), QPointF(xPos, mappingLine().y2()));
    175.  
    176. xPos = xPos + 3;
    177. if((xPos + mapperWidth) > visibleRectL.topRight().x()) { // out from right
    178. xPos -= mapperWidth + 4;
    179. }
    180.  
    181. // use setPos_ for animated positioning
    182. mapper()->setPos(QPointF(xPos, 0));
    183.  
    184. mapper()->setDataValues(points);
    185. paint.drawLine(lineToDraw);
    186. }
    187. }
    188.  
    189. paint.end();
    190. }
    191.  
    192. emit image_changed(image);
    193. }
    To copy to clipboard, switch view to plain text mode 

    and on SLOT i have done a simple QImage to QPixmap conversion
    Qt Code:
    1. // pix is the pointer of QPixmap which will draw on QGraphicsItem
    2. *pix = QPixmap::fromImage(image);
    To copy to clipboard, switch view to plain text mode 

    this is everything i have dont with QThread..

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt GraphicsView stop getting paint event

    Ok, but where do you call update() to actually update the UI?
    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. Qt/MFC Event Loop - stop MFC receiving event?
    By Kaylx in forum Qt Programming
    Replies: 1
    Last Post: 26th April 2012, 18:57
  2. Timer event & paint event, priority
    By Teuniz in forum Qt Programming
    Replies: 0
    Last Post: 2nd February 2010, 13:33
  3. Paint event function in key press event
    By soumya in forum Qt Programming
    Replies: 6
    Last Post: 2nd February 2010, 12:40
  4. How to stop event loop of QDialog in Qt4
    By node_ex in forum Qt Programming
    Replies: 3
    Last Post: 8th July 2008, 07:19
  5. function to stop receiving event
    By babu198649 in forum Qt Programming
    Replies: 11
    Last Post: 19th November 2007, 08:45

Tags for this Thread

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.