Results 1 to 6 of 6

Thread: Is there any substitution function for the obsolete QGraphicsScene drawItems ?

  1. #1
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Is there any substitution function for the obsolete QGraphicsScene drawItems ?

    For QGraphicsScene::drawItems the reference says :
    Reimplement this function to provide custom painting of all items for the scene; gaining complete control over how each item is drawn.
    But this function is marked as obsolete .
    Is there any new equivalent method ?
    Last edited by tonnot; 25th November 2011 at 10:22.

  2. #2
    Join Date
    Jul 2014
    Posts
    14
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Is there any substitution function for the obsolete QGraphicsScene drawItems ?

    This would interest me as well.
    I would to hide to small items in a view completely, when the user zooms out.
    Hiding them in the scene would hide them in all views, so drawItems would seem like the right function.

    Is there a replacement for that function?
    Or is there another way for solving this?

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Is there any substitution function for the obsolete QGraphicsScene drawItems ?

    Quote Originally Posted by veiovis View Post
    I would to hide to small items in a view completely, when the user zooms out.
    The proper way to do it is to teach your items to make use of the level-of-detail information provided by the QStyleOptionGraphicsItem::levelOfDetailFromTransform() method and skip drawing parts or whole items when the item is "far enough" from the viewer.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. The following user says thank you to wysota for this useful post:

    veiovis (31st July 2014)

  5. #4
    Join Date
    Jul 2014
    Posts
    14
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Is there any substitution function for the obsolete QGraphicsScene drawItems ?

    Hi, thanks for your reply.
    I did not find this function before. Could be what I need.
    But I tried using it, and it always returned 1.
    I'm scaling my view with QGraphicsView::scale() and this always prints 1 for lod and lodT (level of detail):

    Qt Code:
    1. void RoundRectItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
    2. QWidget *widget)
    3. {
    4. qreal lod = option->levelOfDetail;
    5. qreal lodT = option->levelOfDetailFromTransform(painter->worldTransform());
    6. ARMARX_INFO << "lod: " << lod << " lodT: " << lodT << " width: " << mapRectToScene(bounds).width() << std::endl;
    7. ...
    To copy to clipboard, switch view to plain text mode 

    What am I understanding wrong here?

    Also the paint-function is not called when zooming in or out (kinda suspicious).

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Is there any substitution function for the obsolete QGraphicsScene drawItems ?

    Works quite fine for me:

    Qt Code:
    1. #include <QtWidgets>
    2.  
    3. class Item : public QGraphicsRectItem {
    4. public:
    5. Item(QGraphicsItem *parent = 0) : QGraphicsRectItem(parent) {
    6. setRect(0,0,50,50);
    7. setPen(QPen(Qt::red));
    8. }
    9.  
    10. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) {
    11. qDebug() << "LOD:" << QStyleOptionGraphicsItem::levelOfDetailFromTransform(painter->worldTransform());
    12. QGraphicsRectItem::paint(painter, option, widget);
    13. }
    14. };
    15.  
    16. class GraphicsView : public QGraphicsView {
    17. public:
    18. GraphicsView() : QGraphicsView() {}
    19. protected:
    20. void mousePressEvent(QMouseEvent *e) {
    21. if(e->button() == Qt::LeftButton) scale(2,2);
    22. else scale(0.5, 0.5);
    23. }
    24. };
    25.  
    26. int main(int argc, char **argv) {
    27. QApplication app(argc, argv);
    28. GraphicsView view;
    29. view.setScene(&scene);
    30. scene.addItem(new Item);
    31. view.show();
    32. view.scale(3,3);
    33. return app.exec();
    34. }
    To copy to clipboard, switch view to plain text mode 

    If paint() is not getting called for you then either you may have caching enabled or your paint() signature is incorrect.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. The following user says thank you to wysota for this useful post:

    veiovis (31st July 2014)

  8. #6
    Join Date
    Jul 2014
    Posts
    14
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Is there any substitution function for the obsolete QGraphicsScene drawItems ?

    Paint is called, when resizing my widget or when i drag something over it. Also, all the paint is done in there for my widget and its painted correctly.

    I'll have a look at your code and try to figure out the difference, thanks

    Edit: Your code works for me too...so let the hunt begin


    Added after 10 minutes:


    Caching was the problem:
    Qt Code:
    1. setCacheMode(ItemCoordinateCache);
    To copy to clipboard, switch view to plain text mode 
    I needed to removed that line, thanks.

    Edit: Using DeviceCoordinateCache works also and the paint function is not called as often.
    Last edited by veiovis; 31st July 2014 at 01:25.

Similar Threads

  1. How to ensure I do not use obsolete functions?
    By lalesculiviu in forum Qt Programming
    Replies: 2
    Last Post: 15th September 2011, 17:23
  2. Replies: 9
    Last Post: 17th June 2010, 10:53
  3. Is QWSServer obsolete now?
    By hybrid_snyper in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 20th October 2009, 16:05
  4. Replies: 3
    Last Post: 15th November 2007, 14:09
  5. qDebug macro substitution
    By the_bis in forum Qt Programming
    Replies: 2
    Last Post: 15th November 2006, 09:31

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.