Details
-
Bug
-
Resolution: Duplicate
-
P2: Important
-
4.6.3, 4.7.0
-
None
-
This happens in all environments.
-
4f072e2d3d7e429359ff15a615d02712bff7ee51 1112b5ca9b448ce26cdd9eb7cc67abc7f9d537d8
Description
If the right-most widget you add to a grid layout has a column span > 1, it fails to be placed correctly. The expected behavior is that the span is ignored.
The following code demonstrates the bug. The "Box" widget has a preferred size of (100, 100) and takes a colored background as a construction parameter. One Box is used as a "window" that has a grid layout assigned. We then add three Box items to the grid layout. The first two are "normal" boxes, colors red and green. The final, blue, Box item has a column span of 2.
The example shows that the final widget isn't visible (see screenshot). The same code creates an expected result if you replace QGraphicsGridLayout with QGridLayout and use QWidget instead. It also behaves as expected if you specify a column span of 1 (or don't specify a column span).
#include <QtGui> class Box : public QGraphicsWidget { public: Box(const QColor &color) : col(color) { } void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget * = 0) { painter->fillRect(rect(), col); } protected: QSizeF sizeHint(Qt::SizeHint hint, const QSizeF &constraint = QSizeF(-1, -1)) const { return hint == Qt::PreferredSize ? QSizeF(100, 100) : QGraphicsWidget::sizeHint(hint, constraint); } private: QColor col; }; int main(int argc, char **argv) { QApplication app(argc, argv); Box *window = new Box(Qt::darkYellow); QGraphicsGridLayout *grid = new QGraphicsGridLayout; window->setLayout(grid); grid->addItem(new Box(Qt::red), 0, 0); grid->addItem(new Box(Qt::green), 0, 1); // grid->addItem(new Box(Qt::blue), 0, 2); grid->addItem(new Box(Qt::blue), 0, 2, 1, 2); QGraphicsScene scene; scene.addItem(window); QGraphicsView view(&scene); view.show(); return app.exec(); }
Attachments
Issue Links
- relates to
-
QTBUG-30255 QGraphicsGridLayout span error
-
- Closed
-