PDA

View Full Version : Placing a widget at fixed place on top of QAbstractScrollArea (actually QGV)



Vladimir
29th August 2007, 15:59
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 !

jpn
29th August 2007, 16:08
Hi. Is the widget allocated on the stack? This usually leads to what you describe..


QWidget widget(graphicsView); // <-- wrong
// vs.
QWidget* widget = new QWidget(graphicsView); // <-- correct

Vladimir
29th August 2007, 16:10
No, the widget is allocated on the heap.

jpn
29th August 2007, 16:15
At least this works for me:


#include <QtGui>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

QGraphicsScene scene;
QGraphicsItem* item = scene.addRect(QRectF(0,0,25,25));
item->setFlag(QGraphicsItem::ItemIsMovable);

QGraphicsView view;
view.setScene(&scene);
QLabel* label = new QLabel("Test", &view);
Q_UNUSED(label);

view.show();
return a.exec();
}

Vladimir
29th August 2007, 16:19
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.

jpn
29th August 2007, 16:36
Ok, great that the problem was solved. And no worries, this was not disturbing at all! :)