Results 1 to 5 of 5

Thread: QGraphicsView/Item Tiling Problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2008
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsView/Item Tiling Problem

    I'm placing my items using setPos

    Qt Code:
    1. //------------------------------------------------------------------------------
    2. void WorldGraphicsScene::loadSection(QString section, int x, int y, int width)
    3. {
    4. for(int i = 0; i < 16; i++)
    5. {
    6. for(int j = 0; j < 16; j++)
    7. {
    8. QFileInfo file("resources/world/" + section + "/"
    9. + section + "_" + QVariant(i).toString()
    10. + "_" + QVariant(j).toString() + ".jpg");
    11. ImageItem* image = new ImageItem(file);
    12. image->setPos(x + (i * width), y + (j * width));
    13. image->setEnabled(false);
    14. image->setDrawBorder(false);
    15.  
    16. this->addItem(image);
    17. }
    18. }
    19. }
    To copy to clipboard, switch view to plain text mode 

    My boundingRect looks like this:
    Qt Code:
    1. //------------------------------------------------------------------------------
    2. QRectF BaseItem::boundingRect() const
    3. {
    4. return QRectF(0, 0, Settings::ImageWidth, Settings::ImageWidth);
    5. }
    To copy to clipboard, switch view to plain text mode 

    Do I need to implement the shape method too?

    And here my simplified drawing code:
    Qt Code:
    1. //------------------------------------------------------------------------------
    2. void ImageItem::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget /*= 0*/)
    3. {
    4. QRectF bounds = boundingRect();
    5. painter->drawPixmap(bounds, _image);
    6. }
    To copy to clipboard, switch view to plain text mode 

    I didn't account the pen width since I don't use a pen/outline. Do I have to?

  2. #2
    Join Date
    Jul 2008
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsView/Item Tiling Problem

    nobody?

    I also encountered an other problem: I'm using a QGraphicsView in a QStackedWidget as my centralwidget in a QMainwindow. Now I noticed that the bigger the window gets the slower my application gets. First I thought thats because there is more to display - but there isn't. I'm showing the exact same thing (couple pictures which can freely be moved and zoomed). If my window size is lets say 640x480 and I'm displaying 20 pictures its much faster than if my window is 1280x1024 and I'm displaying 20 pictures (in the exact same zoom level). Am I doing something wrong?

Similar Threads

  1. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 10:12
  2. Steps in solving a programming problem?
    By triperzonak in forum General Programming
    Replies: 8
    Last Post: 5th August 2008, 09:47
  3. Replies: 16
    Last Post: 7th March 2006, 16:57

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
  •  
Qt is a trademark of The Qt Company.