Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-864

Layout regression on Mac

    XMLWordPrintable

Details

    • macOS

    Description

      The following example demonstrates a bug on MacOSX with 4.3.0.

      Running on other platforms or with 4.2.x it works as expected:

      #include <QtGui>

      class Editor : public QWidget
      {
      Q_OBJECT

      public:
      Editor(QWidget * parent = 0)
      : QWidget(parent)

      { QHBoxLayout *layout = new QHBoxLayout(this); layout->setMargin(0); layout->setSpacing(0); QLineEdit *lineEdit = new QLineEdit(this); lineEdit->setFrame(0); QPushButton *pushButton = new QPushButton(QString("..."), this); pushButton->setMaximumWidth(16); layout->addWidget(lineEdit); layout->addWidget(pushButton); }

      };

      class Delegate : public QItemDelegate
      {
      Q_OBJECT
      public:
      Delegate(QObject *parent = 0)
      : QItemDelegate(parent)
      {}
      QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &) const

      { return new Editor(parent); }

      QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const

      { return QItemDelegate::sizeHint(option, index) + QSize(0, 4); }

      };

      #include "main.moc"

      int main(int argc, char *argv[])
      {
      QApplication app(argc, argv);
      QStandardItemModel model(4, 2);
      QTreeView treeView;
      treeView.setModel(&model);
      Delegate delegate;
      treeView.setItemDelegate(&delegate);
      for (int row = 0; row < 4; ++row) {
      for (int column = 0; column < 2; ++column)

      { QModelIndex index = model.index(row, column, QModelIndex()); model.setData(index, QVariant((row+1) * (column+1))); }

      }
      treeView.show();
      return app.exec();
      }

      To reproduce:

      start app
      double click on a cell to start editing
      notice how the lineedit doesn't use all the available space

      This patch prevents the problem:

      — /tmp/tmp.18648.11 2007-07-10 16:34:15.000000000 -0700
      +++ /Users/anders/dev/qt-4.3/src/gui/kernel/qboxlayout.cpp 2007-07-10 16:24:34.000000000 -0700
      @@ -132,6 +132,7 @@ void QBoxLayoutPrivate::effectiveMargins
      int t = topMargin;
      int r = rightMargin;
      int b = bottomMargin;
      +#if 0
      #ifdef Q_WS_MAC
      Q_Q(const QBoxLayout);
      if (horz(dir))

      { @@ -221,6 +222,7 @@ void QBoxLayoutPrivate::effectiveMargins }


      }
      #endif
      +#endif
      if (left)
      *left = l;
      if (top)

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            bjnilsen Bjørn Erik Nilsen
            rve Anders Bakken
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes