Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved]GraphicsWidget & GraphicsScene - auto resizing
Forum Updated to NodeBB v4.3 + New Features

[Solved]GraphicsWidget & GraphicsScene - auto resizing

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 2.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Peppy
    wrote on last edited by
    #1

    Is any way to autoresize GraphicsWidget by resizeEvent of main window there??

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      ZapB
      wrote on last edited by
      #2

      Yes. Basically you do this:

      • Derive a class from QGraphicsView, MyGraphicsView, say.
      • Use this instead of QGraphicsView in your application. Remember to add this to a layout in your application widget hierarchy so that the MyGraphicsView gets resize events as the mainwindow is resized.
      • Override the resizeEvent( QResizeEvent* ) function in your MyGraphicsView class and do something like this:

      @
      void MyGraphicsView::resizeEvent( QResizeEvent* e )
      {
      double w = ( e->size().width() - 20.0 );
      double h = ( e->size().height() - 20.0 );
      m_myGraphicsWidget->resize( w, h );
      }
      @

      You may also want to update the QGraphicsScene's sceneRect in that function too so that it closely bounds the resulting scene. It depends on your item/widget hierarchy what you want to do though.

      Nokia Certified Qt Specialist
      Interested in hearing about Qt related work

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved