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. how to add qgraphicscene/view to qwidget
Forum Updated to NodeBB v4.3 + New Features

how to add qgraphicscene/view to qwidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 678 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.
  • S Offline
    S Offline
    s002wjh
    wrote on last edited by
    #1

    how do i add qgraphicscene/view to qwidget

    for example, this create a separate window than wdiget.

    scene and view are qgraphicscene and qgraphicview declare in mytest_widget class

    mytest_widget::mytest_widget(QWidget *parent) : QWidget(parent)
    {
    rect = new QGraphicsRectItem();

    scene.addItem(rect);

    view.setScene(scene);
    view.show();
    }

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Take a look at the Layout Management chapter in Qt's documentation.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • S Offline
        S Offline
        s002wjh
        wrote on last edited by s002wjh
        #3

        thx, i look at it, but it didn't mention qgraphscene. i add QHBoxLayout etc before with button etc, but not sure about qgraphicscene?

        something like this

        mytest_widget::mytest_widget(QWidget *parent) : QWidget(parent)
        {
        mytest_widget_dis *display = new mytest_widget_dis();
        display->view->show();
        QVBoxLayout *mainLayout = new QVBoxLayout;

        mainLayout->addWidget( display );

        }

        mytest_widget_dis::mytest_widget_dis(QWidget *parent)

        {
        rect = new QGraphicsRectItem();
        rect->setRect(0,0,100,100);
        rect->setBrush(Qt::black);
        pen.setColor(Qt::green);
        rect->setPen(pen);
        scene = new QGraphicsScene(this);
        scene->addItem(rect);

        view=new QGraphicsView(scene);

        }

        thought Scene still show a separated GUI from main widget

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You are not setting your layout on the widget.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1

          • Login

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