tiredtyrant
11th February 2010, 18:16
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:
layoutWidget(QWidget *parent = 0);
};
layoutwidget.cpp
#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);
}
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);
QApplication app(argc, argv);
layoutWidget window;
window.show();
return app.exec();
}
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?
layoutwidget.h
class layoutWidget : public QWidget{
public:
layoutWidget(QWidget *parent = 0);
};
layoutwidget.cpp
#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);
}
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);
QApplication app(argc, argv);
layoutWidget window;
window.show();
return app.exec();
}
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?