Results 1 to 5 of 5

Thread: Issue in placing the QGraphicsItems into QGraphicsLayout

  1. #1
    Join Date
    Apr 2009
    Posts
    8
    Qt products
    Qt3
    Platforms
    Windows

    Default Issue in placing the QGraphicsItems into QGraphicsLayout

    I am using QGraphicsGridLayout in GraphicScene(class publicly inherited from QGraphicsScene)..

    I have to place a QPushButton in column 1 of the QGraphicsGridLayout in all the rows. And want to place a QGraphicsItem into column 2 of each row..

    I am able to see the two QPushButton one below another (after adding them in the QGraphicsGridLayout), but when i try to add the QGraphicsItem (GraphicsItem). they are placed at zero location of the scene.. And are not placed in the particular grid column location.

    I don't want use the hard coded location (using setpos() ) for the QGraphicsItem. How can i do that?

    Code snap shot:
    ================================
    GraphicScene::GraphicScene(QWidget *parent)
    {
    setItemIndexMethod(QGraphicsScene::NoIndex);
    setSceneRect(0, 0, 800, 1200);

    graphics_scene_layout = new QGraphicsGridLayout();

    QGraphicsProxyWidget *proxy_p_button_0 = new QGraphicsProxyWidget();
    QGraphicsProxyWidget *proxy_p_button_1 = new QGraphicsProxyWidget();
    QGraphicsProxyWidget *proxy_graphicsitem_0 = new QGraphicsProxyWidget();
    QGraphicsProxyWidget *proxy_graphicsitem_1 = new QGraphicsProxyWidget();

    QPushButton *p_button_0 = new QPushButton("-");
    p_button_0->resize(20,20);

    QPushButton *p_button_1 = new QPushButton("-");
    p_button_1->resize(20,20);

    proxy_p_button_0->setWidget(p_button_0);
    proxy_p_button_1->setWidget(p_button_1);

    p_button_0->show();
    p_button_1->show();

    graphics_scene_layout->addItem(proxy_p_button_0, 0, 0, Qt::AlignLeft | Qt::AlignTop);
    graphics_scene_layout->addItem(proxy_p_button_1, 1, 0, Qt::AlignLeft | Qt::AlignTop);

    GraphicsItem *item0 = new GraphicsItem(parent);
    GraphicsItem *item1 = new GraphicsItem(parent);

    proxy_graphicsitem_0->setGraphicsItem(item0);
    proxy_graphicsitem_1->setGraphicsItem(item1);

    graphics_scene_layout->addItem(proxy_graphicsitem_0, 0, 1);
    graphics_scene_layout->addItem(proxy_graphicsitem_1, 1, 1);

    QGraphicsWidget *form = new QGraphicsWidget;
    form->setLayout(graphics_scene_layout);
    this->addItem(form);
    }

    ================================


    Am i missing some thing?? I was expecting placing the item in correct gird row/column will take care of position in scene.

    Thanks in Advance!

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Issue in placing the QGraphicsItems into QGraphicsLayout

    I think you need to create a graphics layout item subclass and implement the setGraphicsItem there.

  3. #3
    Join Date
    Apr 2009
    Posts
    8
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: Issue in placing the QGraphicsItems into QGraphicsLayout

    Sorry i could not understand exactly what you meant to say..

    Shall i create GraphicsItem by inheriting QGraphicsLayoutItem instead of QGraphicsItem?
    If Yes, I've already tried it.

    The GraphicsItem, created is a customized QGraphicsItem created by me and A text has to be set into it. If i use the QGraphicsLayoutItem instead of QGraphicsItem.
    This is customizations are not possible.

    Also, if the QPushbutton are placed automatically at proper location in layout.
    Whats is the problem with QGraphicsItem??

    I also want to ask, can i insert another QGraphicsScene in the QGraphicsGridLayout?

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Issue in placing the QGraphicsItems into QGraphicsLayout

    A layout in Qt does not directly contain any widgets or, in this case, graphics items.
    You need to put the widget or graphics item in a container, which is called a layout item.

    The layout only uses layout items or other layouts to do the actual work.

    This means that you can leave your custom item exactly as it is right now.
    What you do need to create is a custom layout item. This layout item will contain your custom graphics item and report to the acual layout the size of your custom item, among other things.

    Qt Code:
    1. +------------------------------------------------------------+
    2. | Layout |
    3. | |
    4. | +-----------------------------------------------+ |
    5. | | Layout Item | |
    6. | | | |
    7. | | +--------------------+ | |
    8. | | | Graphics Item | | |
    9. | | +--------------------+ | |
    10. | +-----------------------------------------------+ |
    11. | |
    12. | +-----------------------------------------------+ |
    13. | | Layout Item | |
    14. | | | |
    15. | | +--------------------+ | |
    16. | | | Graphics Item | | |
    17. | | +--------------------+ | |
    18. | +-----------------------------------------------+ |
    19. | |
    20. +------------------------------------------------------------+
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Apr 2009
    Posts
    8
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: Issue in placing the QGraphicsItems into QGraphicsLayout

    Thank you very much for the help. Will do the necessary changes.

Similar Threads

  1. QGraphicsLayout: Problems adding QLabel
    By SneakyPeterson in forum Newbie
    Replies: 1
    Last Post: 1st July 2010, 13:31
  2. Replies: 6
    Last Post: 16th February 2010, 19:21
  3. QGraphicsLayout::geometry()
    By isutruk in forum Qt Programming
    Replies: 1
    Last Post: 19th October 2009, 16:43
  4. qt 4.4 Issue with too many QGraphicsItems
    By spawn9997 in forum Qt Programming
    Replies: 6
    Last Post: 2nd September 2009, 16:56
  5. Extending QGraphicsLayout
    By Darkman in forum Qt Programming
    Replies: 0
    Last Post: 13th March 2009, 13:09

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.