I have a QWidget (myWidget) which contains only a QLabel (myLabel) inside of it. There is no layout around myLabel (myLabel must to be free because I want move it anywhere inside myWidget). So, I put myWidget inside a QGraphicsView (trought a QGraphicsScene). Then I set the position of myLabel this way:
ui->myLabel->move(-10, 0);
The result is that only the final part of myLabel is visible (the initial 10 pixels are not shown on the screen because they are out the myWidget). That’s exactly what I was expecting. But since I’m working with QGraphicsView, I should use QGraphicsProxyWidget (which is a QGraphicsItem) to manipulate the position and to make animation on my widgets. So, what I did:
QGraphicsProxyWidget *myLabelProxy = this->createProxyForChildWidget(ui->myLabel);
myLabeProxy->setPos(-10, 0);
The result is that myLabel is entire visible now. Even the initial 10 pixels which should be hidden because they are outside myWidget. I want that only the parts that are inside the parents widgets boundaries to be visible. Remeber that I wanna use QGraphicsProxyWidget to manipulating the position and to make animations on my widgets to avoid undesirable side effects…
I want to happen the same behavior of the first situation.

A simple example (run this way and later comment the indicated line and uncommented the other 2 lines):

Qt Code:
  1. #include <QtGui>
  2. int main(int argc, char *argv[])
  3. {
  4. QApplication a(argc, argv);
  5. QWidget *w = new QWidget();
  6. QHBoxLayout *layout = new QHBoxLayout();
  7. w->setLayout(layout);
  8. layout->addWidget(view);
  9. view->setScene(scene);
  10. QWidget *myWidget = new QWidget();
  11. myWidget->setGeometry(0, 0, 200, 100);
  12. scene->addWidget(myWidget);
  13. QLabel *myLabel = new QLabel(“Text of the Label!!!”, myWidget);
  14. myLabel->show();
  15. //run with this line commented later
  16. myLabel->move(-10, 0);
  17. //uncomment these 2 lines later
  18. // QGraphicsProxyWidget *myLabelProxy = myWidget->graphicsProxyWidget()->createProxyForChildWidget(myLabel);
  19. // myLabelProxy->setPos(-10, 0);
  20. w->showMaximized();
  21. return a.exec();
  22. }
To copy to clipboard, switch view to plain text mode