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
class layoutWidget
: public QWidget{ public:
};
class layoutWidget : public QWidget{
public:
layoutWidget(QWidget *parent = 0);
};
To copy to clipboard, switch view to plain text mode
layoutwidget.cpp
#include "layoutwidget.h"
#include <QVBoxLayout>
#include <QPushButton>
#include <QScrollArea>
#include <QPalette>
{
box->setSpacing(1);
box->addWidget(pb);
DragWidget *window = new DragWidget(this);
scroll
->setBackgroundRole
(QPalette::Light);
scroll->setWidget(window);
box->addWidget(scroll);
setLayout(box);
}
#include "layoutwidget.h"
#include <QVBoxLayout>
#include <QPushButton>
#include <QScrollArea>
#include <QPalette>
layoutWidget::layoutWidget(QWidget *parent) : QWidget(parent)
{
QScrollArea *scroll = new QScrollArea();
QVBoxLayout *box = new QVBoxLayout(this);
box->setSpacing(1);
QPushButton *pb = new QPushButton("hello world",this);
box->addWidget(pb);
DragWidget *window = new DragWidget(this);
scroll->setBackgroundRole(QPalette::Light);
scroll->setWidget(window);
box->addWidget(scroll);
setLayout(box);
}
To copy to clipboard, switch view to plain text mode
The only other thing i modified from the example was the main function:
#include <QApplication>
#include <QVBoxLayout>
#include "dragwidget.h"
#include "layoutwidget.h"
int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(fridgemagnets);
layoutWidget window;
window.show();
return app.exec();
}
#include <QApplication>
#include <QVBoxLayout>
#include "dragwidget.h"
#include "layoutwidget.h"
int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(fridgemagnets);
QApplication app(argc, argv);
layoutWidget window;
window.show();
return app.exec();
}
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?
Bookmarks