[Qt-interest] QGraphicsItem not paint
Riccardo Roasio
riccardo.roasio at gmail.com
Mon Sep 28 16:46:24 CEST 2009
Hi,
i have a QGRaphincsItem that create a chld on paint action.
The problem is that the child is not painted on screen (the functuion
paint is never called for the child)
Can someone help me solving this issue?
Tahnsk so much
The piece of code is this one:
#ifndef CALCULATORSCREEN_H
#define CALCULATORSCREEN_H
#include <QGraphicsItem>
#include <QGraphicsScene>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsSceneHoverEvent>
#include <QPainter>
#include <QStyleOption>
#include <QPointF>
#include <QList>
#include <QPixmap>
#include <iostream>
#include "calculatorscreentopbuttonarea.h"
class CalculatorScreen: public QGraphicsItem
{
public:
CalculatorScreen(QGraphicsScene *s,QString id);
void paint(QPainter *painter, const QStyleOptionGraphicsItem
*option, QWidget *widget);
QRectF boundingRect() const;
QPainterPath shape() const;
protected:
private:
QGraphicsScene *scene;
QString table_name;
CalculatorScreenTopButtonArea *top;
};
#ifndef CALCULATORSCREENTOPBUTTONAREA_H
#define CALCULATORSCREENTOPBUTTONAREA_H
#include <QGraphicsItem>
#include <QGraphicsScene>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsSceneHoverEvent>
#include <QPainter>
#include <QStyleOption>
#include <QPointF>
#include <QList>
#include <QPixmap>
#include <iostream>
class CalculatorScreenTopButtonArea: public QGraphicsItem
{
public:
CalculatorScreenTopButtonArea(QGraphicsScene *s,QString id);
void paint(QPainter *painter, const QStyleOptionGraphicsItem
*option, QWidget *widget);
QRectF boundingRect() const;
QPainterPath shape() const;
protected:
private:
QGraphicsScene *scene;
QString table_name;
};
#endif // CALCULATORSCREENTOPBUTTONAREA_H
#include "calculatorscreentopbuttonarea.h"
CalculatorScreenTopButtonArea::CalculatorScreenTopButtonArea(QGraphicsScene
*s,QString id)
{
std::cout<<"Top"<<std::endl;
table_name=id;
scene=s;
setZValue(2);
}
QRectF CalculatorScreenTopButtonArea::boundingRect() const
{
return QRectF( 0, 0, 1000, 50);;
}
QPainterPath CalculatorScreenTopButtonArea::shape() const
{
QPainterPath path;
path.addRect( 0, 0, 1000, 50);;
return path;
}
void CalculatorScreenTopButtonArea::paint(QPainter *painter, const
QStyleOptionGraphicsItem *option, QWidget *)
{
std::cout<<"Drawing"<<std::endl;
painter->setBrush(QColor(0,0,0,255));
painter->setPen(QPen(Qt::black, 0));
painter->drawRect( 0, 0, 1000, 50);
}
More information about the Qt-interest-old
mailing list