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

QGraphicsView clips a widget that is owned by the viewport when resizing

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.14.2
    • Widgets: GraphicsView
    • None

    Description

      When the QGraphicsView is resized, and it's viewport owns a widget that is aligned right by setting the left content margin, resizing the QGraphicsView to any width wider than it's initial width causes the widget to be clipped.

      The following is a minimum working example where a QLabel displaying a pixmap gets clipped when resizing the application wider.

        class MyGraphicsView : public QGraphicsView
      {
      public:
      MyGraphicsView()
      : pm(":/image.svg")
      , compass(new QLabel(viewport()))

      { compass->setPixmap(pm); }

      private:
      void resizeEvent(QResizeEvent* event) override

      { QGraphicsView::resizeEvent(event); QMargins margins = compass->contentsMargins(); margins.setLeft(viewport()->width() - pm.width() - 2); compass->setContentsMargins(margins); }

      QLabel* compass;
      QPixmap pm;
      };

      int main(int argc, char *argv[])

      { QApplication app(argc, argv); QMainWindow win; win.setCentralWidget(new MyGraphicsView()); win.show(); return app.exec(); }

      Attachments

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

        Activity

          People

            bibr Andreas Aardal Hanssen
            sgw136 Steve Wagner
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes