PDA

View Full Version : Issue with QGraphicsLinearLayout (Qt-4.4 snapshot)



momesana
4th January 2008, 14:07
I went through the ordeal of downloading a recent Qt-4.4.0 snapshot (it's about two days old) over a 56kbit modem line in order to test the new QGraphicsView capabilities. I was most interested in using the Widget on canvas feature and the new QGraphics-layout-managers. None of them work for me. I will focus on the issue with the linearLayout in this post.
I have pasted a little application below that highlights my problems. The layout works in so far that the QGraphicsWidgets are placed into the layout and handled properly. But the setSpacing member doesn't work as expected. If I set a spacing of 0, then all the items are painted on top of each other so that the result looks like a single item while the default spacing of 4 pixels creates a condensed heap of items. I have to resort to a spacing greater then the size of the items themselves in order to make them appear side by side. What am I doing wrong?

Thanx in advance



#include <QtGui>

class Panel : public QGraphicsWidget
{
Q_OBJECT
public:
Panel(QGraphicsItem * parent = 0, Qt::WindowFlags wFlags = 0) :
QGraphicsWidget(parent, wFlags) {
rect = QRectF(0, 0, 40, 40);
setGeometry(rect);
}
void paint(QPainter* painter,
const QStyleOptionGraphicsItem*, QWidget* widget = 0) {
Q_UNUSED(widget);
painter->setRenderHints(QPainter::Antialiasing);
QPen pen(Qt::black);
pen.setWidth(1);
painter->setPen(pen);
painter->setBrush(Qt::BDiagPattern);
painter->drawEllipse(rect);
}
private:
QRectF rect;
};

class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget* parent=0) : QMainWindow(parent) {
resize(800, 600);
QGraphicsScene* scene = new QGraphicsScene;
QGraphicsWidget* container = new QGraphicsWidget;
m_lo = new QGraphicsLinearLayout;
m_lo->setOrientation(Qt::Horizontal);
m_lo->setSpacing(30);
container->setLayout(m_lo);
scene->addItem(container);
for (int i = 0; i < 10; i++) {
QGraphicsLinearLayout* row = new QGraphicsLinearLayout;
row->setOrientation(Qt::Vertical);
row->setSpacing(30);
m_lo->addItem(row);
for (int j = 0; j < 10; j++) {
Panel* p = new Panel;
row->addItem(p);
}
}
QGraphicsView* view = new QGraphicsView(scene);
setCentralWidget(view);
}
private:
QGraphicsLinearLayout* m_lo;
};

int main(int argc, char** argv)
{
QApplication app(argc, argv);
MainWindow mw;
mw.show();
return app.exec();
}
#include "main.moc"

momesana
5th January 2008, 19:14
Really no Idea on how to deal with this or shouldn't I mess around with pre-releases anyway?

maverick_pol
7th January 2008, 08:46
Hi,

It may be a good idea to look at the pre-release when you're strongly seeking for some feature or are as good as to find errors by yourself. Anyway, good luck. : )

Kacper

momesana
10th January 2008, 03:05
Hi,

It may be a good idea to look at the pre-release when you're strongly seeking for some feature or are as good as to find errors by yourself. Anyway, good luck. : )

Kacper

Well, if you mean the technical preview by pre-release, I also downloaded that. Same issues there. I even do not have the widget on canvas example built that is being praised by so many reviewers on the internet. I wonder what I did wrong when compiling it. But, I don't care too much. In a few months, Qt-4.4 is being released anyway. I just have to be a little patient :).