wagmare
7th May 2009, 07:38
hi friends,
i have a problem in positioning an rect item (0, 0, 20, 150) in a graphicsScene() of size (0, 0, 1024, 1024)
DiagView::DiagView(QWidget *parent)
: QGraphicsView(parent)
{
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOf f);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff) ;
setCacheMode(CacheBackground);
setViewportUpdateMode(FullViewportUpdate);
setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
setStyleSheet("background:#336699");
QRectF bounds(0, 0, 1024, 1024);
scene = new QGraphicsScene(bounds, this);
setScene(scene);
item1 = new SlotItem(QRectF(0, 0, 20, 150));
item1->setPos(10,180);
scene->addItem(item1);
}
void DiagView::resizeEvent(QResizeEvent *event)
{
QGraphicsView::resizeEvent(event);
fitInView(scene->sceneRect(), Qt::KeepAspectRatio);
}
slotitem.cpp
SlotItem::SlotItem(const QRectF &rect)
: QGraphicsRectItem(rect)
{
}
void SlotItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
painter->setBrush(QColor(0, 102, 153));
painter->drawRoundRect(rect());
}
QRectF SlotItem::boundingRect()
{
return QRectF(0,0, 50,300);
}
main.cpp
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
DiagView *dialog = new DiagView();
dialog->setGeometry(0, 0, 1024, 1024);
dialog->show();
return app.exec();
}
but the SlotItem is shown in the center of the view port because of the resize event .. if i dont use resize event it positioned the item acurately ... but i need the resize event in future ... what went wrong in my code .. please any one help me ...
i have a problem in positioning an rect item (0, 0, 20, 150) in a graphicsScene() of size (0, 0, 1024, 1024)
DiagView::DiagView(QWidget *parent)
: QGraphicsView(parent)
{
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOf f);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff) ;
setCacheMode(CacheBackground);
setViewportUpdateMode(FullViewportUpdate);
setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
setStyleSheet("background:#336699");
QRectF bounds(0, 0, 1024, 1024);
scene = new QGraphicsScene(bounds, this);
setScene(scene);
item1 = new SlotItem(QRectF(0, 0, 20, 150));
item1->setPos(10,180);
scene->addItem(item1);
}
void DiagView::resizeEvent(QResizeEvent *event)
{
QGraphicsView::resizeEvent(event);
fitInView(scene->sceneRect(), Qt::KeepAspectRatio);
}
slotitem.cpp
SlotItem::SlotItem(const QRectF &rect)
: QGraphicsRectItem(rect)
{
}
void SlotItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
painter->setBrush(QColor(0, 102, 153));
painter->drawRoundRect(rect());
}
QRectF SlotItem::boundingRect()
{
return QRectF(0,0, 50,300);
}
main.cpp
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
DiagView *dialog = new DiagView();
dialog->setGeometry(0, 0, 1024, 1024);
dialog->show();
return app.exec();
}
but the SlotItem is shown in the center of the view port because of the resize event .. if i dont use resize event it positioned the item acurately ... but i need the resize event in future ... what went wrong in my code .. please any one help me ...