Details
-
Bug
-
Resolution: Done
-
P2: Important
-
4.7.0, 5.4.0
-
Mac OS X 10.6.4, OS X 10.9.5
Description
In the example below, the widgets in the QHBoxLayout are drawn overlapping one another. Note that if you change the derivation of MyButton from QPushButton to QAbstractButton, the problem goes away.
main.cpp
#include <QtGui> class MyButton : public QPushButton { public: explicit MyButton(Qt::GlobalColor color, QWidget *parent = NULL) : QPushButton(parent), color_(color) { setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); } QSize sizeHint() const { return QSize(50, 25); } protected: void paintEvent(QPaintEvent *) { QPainter painter(this); painter.setOpacity(0.5); painter.fillRect(0, 0, width(), height(), color_); } private: Qt::GlobalColor color_; }; int main(int argc, char **argv) { QApplication app(argc, argv); QWidget widget; QHBoxLayout *layout = new QHBoxLayout; layout->setSpacing(0); MyButton *w1 = new MyButton(Qt::red); MyButton *w2 = new MyButton(Qt::green); MyButton *w3 = new MyButton(Qt::blue); layout->addWidget(w1); layout->addWidget(w2); layout->addWidget(w3); widget.setLayout(layout); widget.show(); return app.exec(); }
See http://stackoverflow.com/questions/3978889/why-is-qhboxlayout-causing-widgets-to-overlap for screen shot.
Attachments
Issue Links
- relates to
-
QTBUG-126045 Widgets: items inside nested sub layouts are misaligned
- Open