Results 1 to 5 of 5

Thread: Creating a widget on a QGraphicsView

  1. #1
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Creating a widget on a QGraphicsView

    Hi guys,

    I would like to paint a transparent widget(with crossPattern) on the QGraphicsView. I create a widget with QGraphicsView as its' parent, but nothing happens. While moving on the view I can't move on the exact rectangle where I specify the widget, but I can't see it. What is more I do not want that to happend; the widget should not accept any focus etc.

    Here is a piece of code,

    Qt Code:
    1. QWidget* panel;
    2. panel = new QWidget(m_view);//m_view is the QGraphicsView
    3. panel->setPaletteBackgroundColor(Qt::red);
    4. panel->setFixedHeight(100);
    5. panel->setFixedWidth(100);
    6. panel->setBackgroundColor(Qt::red);
    7. panel->setPaletteForegroundColor(Qt::red);
    8. panel->setVisible(true);
    9. panel->show();
    To copy to clipboard, switch view to plain text mode 

    How to make the widget visible?
    How to force the widget to ignore any focus/mouseOver/mouseMove events?

    Maverick
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Creating a widget on a QGraphicsView

    How to make the widget visible?
    Since there isn't any layout to manage the widget's position and size, you have to do it manually, with move() or setGeometry().
    You should move it in the desired position above the graphics view.

    How to force the widget to ignore any focus/mouseOver/mouseMove events?
    Disable the widget. It won't receive any mouse or keyboard events.

  3. #3
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Creating a widget on a QGraphicsView

    Hi,

    Thanks for advice, but still I do not see my widget. There is 'something transparent" on or under the widget, but I do not see it.

    Maverick
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Creating a widget on a QGraphicsView

    You create the widget with the gv as parent. If you accidentally position this widget outside the bounds of the parent it will get clipped( you won't see it at all ).
    So, double check you give the correct coordinates( try (0,0)).

    Or, to make sure everything is ok with the widget and it can be seen, create it with a NULL parent and give it some position. It should appear at that position.

    Regards

  5. #5
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Creating a widget on a QGraphicsView

    Quote Originally Posted by maverick_pol View Post
    Hi guys,
    How to make the widget visible?
    May be you should use m_view->viewport() as the parent of your widget.
    How to force the widget to ignore any focus/mouseOver/mouseMove events?
    Maverick
    You can follow Marcel's idea. You can also install event filter which ignores all the events so that you can have enabled look, yet ignore the events.
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

Similar Threads

  1. Creating a square sized widget in a layout
    By cboles in forum Qt Programming
    Replies: 5
    Last Post: 23rd September 2008, 00:38
  2. Replies: 4
    Last Post: 9th August 2007, 09:20
  3. widget qgraphicsview scaling
    By mistertoony in forum Qt Programming
    Replies: 10
    Last Post: 20th March 2007, 23:46
  4. Creating advanced widget in a delegate.
    By bunjee in forum Qt Programming
    Replies: 8
    Last Post: 5th February 2007, 09:09
  5. [Qt 4.1.0] Split a widget on demand
    By Townk in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2006, 15:16

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.