I tried to modify the Fridge Magnets example of a drag-and-drop application by adding scrolling capabilities to it. What I did was create a new layout class, and add the draggable widget to it. Here is the code for this class:

layoutwidget.h

Qt Code:
  1. class layoutWidget : public QWidget{
  2. public:
  3. layoutWidget(QWidget *parent = 0);
  4. };
To copy to clipboard, switch view to plain text mode 

layoutwidget.cpp

Qt Code:
  1. #include "layoutwidget.h"
  2. #include <QVBoxLayout>
  3. #include <QPushButton>
  4. #include <QScrollArea>
  5. #include <QPalette>
  6.  
  7. layoutWidget::layoutWidget(QWidget *parent) : QWidget(parent)
  8. {
  9. QScrollArea *scroll = new QScrollArea();
  10.  
  11. QVBoxLayout *box = new QVBoxLayout(this);
  12. box->setSpacing(1);
  13.  
  14. QPushButton *pb = new QPushButton("hello world",this);
  15. box->addWidget(pb);
  16. DragWidget *window = new DragWidget(this);
  17.  
  18.  
  19. scroll->setBackgroundRole(QPalette::Light);
  20. scroll->setWidget(window);
  21.  
  22. box->addWidget(scroll);
  23.  
  24. setLayout(box);
  25. }
To copy to clipboard, switch view to plain text mode 

The only other thing i modified from the example was the main function:

Qt Code:
  1. #include <QApplication>
  2. #include <QVBoxLayout>
  3. #include "dragwidget.h"
  4. #include "layoutwidget.h"
  5.  
  6. int main(int argc, char *argv[])
  7. {
  8. Q_INIT_RESOURCE(fridgemagnets);
  9.  
  10. QApplication app(argc, argv);
  11. layoutWidget window;
  12. window.show();
  13. return app.exec();
  14. }
To copy to clipboard, switch view to plain text mode 

At first, it worked nicely. I've added several words to the words.txt list used by the example program, and it worked as expected, at least vertically. But when i inserted huge words that made very long labels, they didn't get rendered in its entirety, the long labels got cut. What can I do to fix it?