Results 1 to 6 of 6

Thread: Placing a widget at fixed place on top of QAbstractScrollArea (actually QGV)

  1. #1
    Join Date
    Jan 2007
    Posts
    45
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Placing a widget at fixed place on top of QAbstractScrollArea (actually QGV)

    Hello All,

    I'm trying to place a widget on top of QAbstractScrollArea but make this widget non-moveable when user moves scroll-bars. I've tried to make in a child widget of QAbstractScrollArea inself and viewport and I've tried to call raise() for my widget - in all cases it appears only for a moment when creating window and then gets covered by viewport. I've event tried to use setViewportMargins() - the same effect.

    Are there any suggestions ?
    Thanks in advance !

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Placing a widget at fixed place on top of QAbstractScrollArea (actually QGV)

    Hi. Is the widget allocated on the stack? This usually leads to what you describe..
    Qt Code:
    1. QWidget widget(graphicsView); // <-- wrong
    2. // vs.
    3. QWidget* widget = new QWidget(graphicsView); // <-- correct
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. #3
    Join Date
    Jan 2007
    Posts
    45
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Placing a widget at fixed place on top of QAbstractScrollArea (actually QGV)

    No, the widget is allocated on the heap.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Placing a widget at fixed place on top of QAbstractScrollArea (actually QGV)

    At least this works for me:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QApplication a(argc, argv);
    6.  
    7. QGraphicsItem* item = scene.addRect(QRectF(0,0,25,25));
    8. item->setFlag(QGraphicsItem::ItemIsMovable);
    9.  
    10. view.setScene(&scene);
    11. QLabel* label = new QLabel("Test", &view);
    12. Q_UNUSED(label);
    13.  
    14. view.show();
    15. return a.exec();
    16. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  5. #5
    Join Date
    Jan 2007
    Posts
    45
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Placing a widget at fixed place on top of QAbstractScrollArea (actually QGV)

    Yes, your code works for me too. It seems that I've found a reason for my problem: I've created a widget from QGraphicsView-derived class constructor and viewport was created after it and after raise() call - so my widget was simply covered by viewport. Sorry for disturbing you.

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Placing a widget at fixed place on top of QAbstractScrollArea (actually QGV)

    Ok, great that the problem was solved. And no worries, this was not disturbing at all!
    J-P Nurmi

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.