Results 1 to 5 of 5

Thread: problem in positioning item in QGraphicsScene()

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    658
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default problem in positioning item in QGraphicsScene()

    hi friends,
    i have a problem in positioning an rect item (0, 0, 20, 150) in a graphicsScene() of size (0, 0, 1024, 1024)

    Qt Code:
    1. DiagView::DiagView(QWidget *parent)
    2. : QGraphicsView(parent)
    3.  
    4. {
    5. setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    6. setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    7. setCacheMode(CacheBackground);
    8. setViewportUpdateMode(FullViewportUpdate);
    9. setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
    10. setStyleSheet("background:#336699");
    11. QRectF bounds(0, 0, 1024, 1024);
    12. scene = new QGraphicsScene(bounds, this);
    13. setScene(scene);
    14.  
    15. item1 = new SlotItem(QRectF(0, 0, 20, 150));
    16. item1->setPos(10,180);
    17. scene->addItem(item1);
    18. }
    19. void DiagView::resizeEvent(QResizeEvent *event)
    20. {
    21. QGraphicsView::resizeEvent(event);
    22. fitInView(scene->sceneRect(), Qt::KeepAspectRatio);
    23. }
    To copy to clipboard, switch view to plain text mode 
    slotitem.cpp
    Qt Code:
    1. SlotItem::SlotItem(const QRectF &rect)
    2. {
    3.  
    4. }
    5. void SlotItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
    6. {
    7. painter->setBrush(QColor(0, 102, 153));
    8. painter->drawRoundRect(rect());
    9.  
    10. }
    11. QRectF SlotItem::boundingRect()
    12. {
    13. return QRectF(0,0, 50,300);
    14.  
    15. }
    To copy to clipboard, switch view to plain text mode 
    main.cpp
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication app(argc, argv);
    4.  
    5. DiagView *dialog = new DiagView();
    6. dialog->setGeometry(0, 0, 1024, 1024);
    7. dialog->show();
    8. return app.exec();
    9. }
    To copy to clipboard, switch view to plain text mode 

    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 ...
    Attached Images Attached Images
    Last edited by wagmare; 7th May 2009 at 09:20. Reason: attached the screen shot image of the window

Similar Threads

  1. QPrinter on QGraphicsScene Border Problem
    By patrik08 in forum Qt Programming
    Replies: 1
    Last Post: 14th November 2007, 15:49
  2. Replies: 1
    Last Post: 19th April 2007, 22:23
  3. problem with "QListWidget" item
    By impeteperry in forum Qt Programming
    Replies: 6
    Last Post: 16th April 2007, 18:00
  4. Moving an item in QGraphicsScene
    By prosass in forum Newbie
    Replies: 4
    Last Post: 28th March 2007, 14:21
  5. QScrollArea problem positioning a QWidget inside
    By Spectator in forum Qt Programming
    Replies: 4
    Last Post: 20th February 2006, 22:59

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.