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)
Re: QGraphicsDropShadowEffect causing a QPainter error
Could you create and post a minimal example application that shows the error?
Joh
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.
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?
Code:
#ifndef GRAPHICSSTACKEDWIDGET_H
#define GRAPHICSSTACKEDWIDGET_H
#include <QStackedWidget>
class GraphicsStackedWidgetPrivate;
{
Q_OBJECT
Q_PROPERTY (int currentIndex READ currentIndex WRITE setCurrentIndex)
Q_PROPERTY (double windowOpacity READ windowOpacity WRITE setWindowOpacity DESIGNABLE isWindow)
private:
GraphicsStackedWidgetPrivate *d;
Q_DECLARE_PRIVATE(GraphicsStackedWidget)
public:
GraphicsStackedWidget
(QWidget *parent
= 0);
~GraphicsStackedWidget();
int currentIndex() const;
Q_INVOKABLE
int addWidget
(QWidget *w
);
public slots:
private slots:
void setCurrentIndex ( int index );
bool hidePage();
void showPage();
};
#endif // GRAPHICSSTACKEDWIDGET_H
-----------------------------------------------------------
#include "graphicsstackedwidget.h"
#include <QtGui>
#include <QGraphicsLinearLayout>
#define TRANSITION_TIME_MS 500
class GraphicsStackedWidgetPrivate
{
public:
int m_index;
GraphicsStackedWidgetPrivate() {
}
};
GraphicsStackedWidget
::GraphicsStackedWidget(QWidget *parent
): d(new GraphicsStackedWidgetPrivate)
{
d->m_index = 0;
}
GraphicsStackedWidget::~GraphicsStackedWidget()
{
delete d;
}
int GraphicsStackedWidget::currentIndex() const
{
}
void GraphicsStackedWidget::setCurrentIndex ( int index )
{
d->m_index = index;
if ( hidePage() ) {
QTimer::singleShot(TRANSITION_TIME_MS
/2,
this,
SLOT(showPage
()));
} else {
showPage();
}
}
int GraphicsStackedWidget
::addWidget(QWidget *w
) {
}
bool GraphicsStackedWidget::hidePage()
{
bool result = false;
if ( oldWidget != NULL ) {
QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect(oldWidget);
oldWidget->setGraphicsEffect(effect);
QPropertyAnimation *animation = new QPropertyAnimation(effect, "opacity", this);
animation->setDuration(TRANSITION_TIME_MS/2);
animation->setStartValue(1);
animation->setEndValue(0);
animation->start();
QTimer::singleShot(TRANSITION_TIME_MS
/2, oldWidget,
SLOT(repaint
()));
result = true;
}
return result;
}
void GraphicsStackedWidget::showPage()
{
if ( widget != NULL ) {
QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect(widget);
widget->setGraphicsEffect(effect);
QPropertyAnimation *animation = new QPropertyAnimation(effect, "opacity", this);
animation->setDuration(TRANSITION_TIME_MS/2);
animation->setStartValue(0);
animation->setEndValue(1);
animation->start();
QTimer::singleShot(TRANSITION_TIME_MS
/2, widget,
SLOT(repaint
()));
}
if ( widget != NULL ) {
widget->update();
}
}
Thanks a lot