Results 1 to 4 of 4

Thread: QGraphicsDropShadowEffect causing a QPainter error

  1. #1
    Join Date
    Mar 2011
    Location
    Denmark
    Posts
    74
    Thanks
    7
    Thanked 10 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default QGraphicsDropShadowEffect causing a QPainter error

    Has anybody come across

    QGraphicsDropShadowEffect throwing the following error?

    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active

    I am adding a bit of flourish in my app and when I try to put a dropshadow on widgets that are in a QStackedWidget (I am not sure if this is what is causing the crash) I am getting a crash in

    void QGraphicsDropShadowEffect::draw(QPainter *painter)

  2. #2
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsDropShadowEffect causing a QPainter error

    Could you create and post a minimal example application that shows the error?

    Joh

  3. #3
    Join Date
    Mar 2011
    Location
    Denmark
    Posts
    74
    Thanks
    7
    Thanked 10 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QGraphicsDropShadowEffect causing a QPainter error

    Unfortunately when I try to reproduce it in a minimal example it doesn't happen, but in my main app it is still there. Can you think of any general scenarios that could trigger something like this?


    Added after 1 4 minutes:


    Also it only happens when I am mousing over the shadowed widget if I just switch between them in the stack panel everything is fine, but something that happens when mousing over triggers the paint errors.
    Last edited by Berryblue031; 23rd March 2011 at 11:35.

  4. #4
    Join Date
    Apr 2008
    Posts
    17
    Thanks
    4

    Default Re: QGraphicsDropShadowEffect causing a QPainter error

    I have the same problem with QGraphicsOpacityEffect on a QStackedWidget. I try to extend QStackedWidget to get fade effects or transitions when you change the page (using currentIndex) on QStackedWidget. But I can't reproduce on a small application.

    This is the code of the extenden QStackedWidget. Are there something wrong?
    Qt Code:
    1. #ifndef GRAPHICSSTACKEDWIDGET_H
    2. #define GRAPHICSSTACKEDWIDGET_H
    3.  
    4. #include <QStackedWidget>
    5.  
    6. class GraphicsStackedWidgetPrivate;
    7.  
    8. class GraphicsStackedWidget : public QStackedWidget
    9. {
    10. Q_OBJECT
    11. Q_PROPERTY (int currentIndex READ currentIndex WRITE setCurrentIndex)
    12. Q_PROPERTY (double windowOpacity READ windowOpacity WRITE setWindowOpacity DESIGNABLE isWindow)
    13.  
    14. private:
    15. GraphicsStackedWidgetPrivate *d;
    16. Q_DECLARE_PRIVATE(GraphicsStackedWidget)
    17.  
    18. public:
    19. GraphicsStackedWidget(QWidget *parent = 0);
    20. ~GraphicsStackedWidget();
    21.  
    22. int currentIndex() const;
    23. Q_INVOKABLE int addWidget(QWidget *w);
    24.  
    25. public slots:
    26.  
    27. private slots:
    28. void setCurrentIndex ( int index );
    29. bool hidePage();
    30. void showPage();
    31. };
    32.  
    33. #endif // GRAPHICSSTACKEDWIDGET_H
    34.  
    35. -----------------------------------------------------------
    36.  
    37. #include "graphicsstackedwidget.h"
    38. #include <QtGui>
    39. #include <QGraphicsLinearLayout>
    40.  
    41. #define TRANSITION_TIME_MS 500
    42.  
    43. class GraphicsStackedWidgetPrivate
    44. {
    45. public:
    46. int m_index;
    47. GraphicsStackedWidgetPrivate() {
    48. }
    49. };
    50.  
    51.  
    52. GraphicsStackedWidget::GraphicsStackedWidget(QWidget *parent):
    53. QStackedWidget(parent),
    54. d(new GraphicsStackedWidgetPrivate)
    55. {
    56. d->m_index = 0;
    57. }
    58.  
    59. GraphicsStackedWidget::~GraphicsStackedWidget()
    60. {
    61. delete d;
    62. }
    63.  
    64. int GraphicsStackedWidget::currentIndex() const
    65. {
    66. return QStackedWidget::currentIndex();
    67. }
    68.  
    69. void GraphicsStackedWidget::setCurrentIndex ( int index )
    70. {
    71. d->m_index = index;
    72. if ( hidePage() ) {
    73. QTimer::singleShot(TRANSITION_TIME_MS/2, this, SLOT(showPage()));
    74. } else {
    75. showPage();
    76. }
    77. }
    78.  
    79. int GraphicsStackedWidget::addWidget(QWidget *w)
    80. {
    81. return QStackedWidget::addWidget(w);
    82. }
    83.  
    84. bool GraphicsStackedWidget::hidePage()
    85. {
    86. bool result = false;
    87. QWidget *oldWidget = QStackedWidget::widget(QStackedWidget::currentIndex());
    88. if ( oldWidget != NULL ) {
    89. QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect(oldWidget);
    90. oldWidget->setGraphicsEffect(effect);
    91. QPropertyAnimation *animation = new QPropertyAnimation(effect, "opacity", this);
    92. animation->setDuration(TRANSITION_TIME_MS/2);
    93. animation->setStartValue(1);
    94. animation->setEndValue(0);
    95. animation->start();
    96. QTimer::singleShot(TRANSITION_TIME_MS/2, oldWidget, SLOT(repaint()));
    97. result = true;
    98. }
    99. return result;
    100. }
    101.  
    102. void GraphicsStackedWidget::showPage()
    103. {
    104. QWidget *widget = QStackedWidget::widget(d->m_index);
    105. if ( widget != NULL ) {
    106. QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect(widget);
    107. widget->setGraphicsEffect(effect);
    108. QPropertyAnimation *animation = new QPropertyAnimation(effect, "opacity", this);
    109. animation->setDuration(TRANSITION_TIME_MS/2);
    110. animation->setStartValue(0);
    111. animation->setEndValue(1);
    112. animation->start();
    113. QTimer::singleShot(TRANSITION_TIME_MS/2, widget, SLOT(repaint()));
    114. }
    115. QStackedWidget::setCurrentIndex(d->m_index);
    116. if ( widget != NULL ) {
    117. widget->update();
    118. }
    119. }
    To copy to clipboard, switch view to plain text mode 

    Thanks a lot

Similar Threads

  1. vector causing system error/crash
    By babygal in forum Newbie
    Replies: 9
    Last Post: 21st October 2010, 08:48
  2. QPainter error: no match for call ...
    By tonnot in forum Newbie
    Replies: 2
    Last Post: 7th October 2010, 13:00
  3. Compile error for Qpainter
    By tonnot in forum Newbie
    Replies: 8
    Last Post: 7th October 2010, 11:37
  4. Replies: 1
    Last Post: 15th January 2010, 16:14
  5. ERROR:: QPainter: Internal error; no available GC
    By Krishnacins in forum Qt Programming
    Replies: 2
    Last Post: 8th March 2006, 07:05

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.