SpamBot
SpamBot

Reputation: 1458

Scrollable background with resizable Qt widgets on it

I would like to create a Qt window that

  1. can be scrolled/panned by dragging its background (scrollbars should not be shown)
  2. contains multiple sub-widgets at defined locations (which scroll with the background)
  3. the sub-widgets can be resized by pulling their border

What I managed so far is to create a QGraphicsView with setDragMode(QGraphicsView::ScrollHandDrag) http://doc.qt.io/qt-5/qgraphicsview.html#dragMode-prop. I then placed the sub-widgets on a QGraphicsScene, however, this didn't allow the sub-widgets to be resized by pulling their border. I also tried to inherit my custom sub-widget class from QDialog, which allows setSizeGripEnabled(true). However, this doesn't resize their content, and QDialog is probably not meant to be part of a QGraphicsView.

Any suggestions? It would also be ok if the sub-widgets behave like sub-windows that can also be dragged at their title bar, as long as they cannot be closed and they move when the background is dragged.

Upvotes: 2

Views: 423

Answers (1)

Kirill Chernikov
Kirill Chernikov

Reputation: 1420

You can look aside QMdiArea class (Qt documentation: QMdiArea). By problem description it is what you need. Of course, you can use Graphics View Framework, but, i think, it will be more difficult. If you choose such approach, very useful will be class QGraphicsWidget (Qt documentation: QGraphicsWidget).

Upvotes: 2

Related Questions