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. Setting up the position of QGraphicsView

Setting up the position of QGraphicsView

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 9.3k Views
  • 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.
  • A Offline
    A Offline
    ananthbangali
    wrote on last edited by
    #1

    Hello everyone. I am a beginner in Qt. Am developing a GUI on linux platform and am using two QGraphicsView in my GUI. I want to know how to set the position of QGraphicsView. As both the graphics view is being overlapped. I would really appreciate if anyone could help me by providing the information on setting the position of QGraphicsView.

    Thanks in advance,

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      Well, you either use "absolute positioning":http://doc.qt.nokia.com/latest/qwidget.html#pos-prop or you use "layouts":http://doc.qt.nokia.com/stable/layout.html.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        ananthbangali
        wrote on last edited by
        #3

        Hi,thanks for your reply.... is their an example code that I code refer to.... as I told you am a beginner it would be really helpful,,

        1 Reply Last reply
        0
        • A Offline
          A Offline
          ananthbangali
          wrote on last edited by
          #4

          the code is as follows:

          @
          graphicsView= new QGraphicsView;
          graphicsView->setSizePolicy(QSizePolicy::Ignored,QSizePolicy::Ignored);
          graphicsView->setGeometry(200,200,200,200);
          graphivsView->setStyleSheet(....);
          @

          [EDIT: code formatting, Volker]

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lgeyer
            wrote on last edited by
            #5

            There are tons of examples found "here":http://doc.qt.nokia.com/stable/all-examples.html and "here":http://doc.qt.nokia.com/stable/tutorials.html.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              ananthbangali
              wrote on last edited by
              #6

              I tried using absolute positioning but its the same result. I also tried using layouts but am getting the comment as program has unexpectedly finished. Please see the code,

              @
              ImageViewer::ImageViewer()
              {
              horizontalLayout = new QHBoxLayout(widget);
              horizontalLayout->setObjectName("horizontalLayout");
              horizontalLayout->setContentsMargins(0, 0, 0, 0);

              graphicsView = new QGraphicsView;//(this);
              graphicsView->setBackgroundRole(QPalette::Base);
              graphicsView->setSizePolicy(QSizePolicy::Ignored,QSizePolicy::Ignored);
              graphicsView->setStatusTip(tr("Area to Display the Image"));
              graphicsView->setGeometry(QRect(10, 40, 256, 192));
              graphicsView->setStyleSheet("color: black;"
                                        "background-color: gray;"
                                        "selection-color: yellow;"
                                        "border: 3px solid black;"
                                        "border-radius: 40px;");
              

              horizontalLayout->addWidget(graphicsView);
              graphicsView1 = new QGraphicsView;//(this);
              graphicsView1->setBackgroundRole(QPalette::Base);
              graphicsView1->setSizePolicy(QSizePolicy::Ignored,QSizePolicy::Ignored);
              graphicsView1->setStatusTip(tr("Area to Display the Image"));
              graphicsView1->setGeometry(QRect(300, 40, 256, 192));
              graphicsView1->setStyleSheet("color: black;"
              "background-color: gray;"
              "selection-color: yellow;"
              "border: 3px solid black;"
              "border-radius: 40px;");
              horizontalLayout->addWidget(graphicsView1);

               scrollArea = new QScrollArea;
               scrollArea->setBackgroundRole(QPalette::Dark);
               scrollArea->setWidget(graphicsView);
               scrollArea->setWidget(graphicsView1);
               scrollArea->setStyleSheet("color:black;");
               //horizontalLayout->addWidget(scrollArea);
              
               setCentralWidget(scrollArea);
              

              ....
              @

              [EDIT: code formatting, Volker]

              1 Reply Last reply
              0
              • L Offline
                L Offline
                lgeyer
                wrote on last edited by
                #7

                At first please wrap your code around @-tags and format it properly. It is an unreadable mess.

                As to your code:

                • You are missing a call to the base class constructor (QMainWindow).
                • horizontalWidget has widget as its parent, which is neither declared nor initialized.
                • QScrollArea can hold just one widget (set... is an indicator that there can be set just one object, add... would be an indicator that there can be set multiple objects).
                • By passing graphicsView1 to QScrollArea::setWidget() graphicsView is deleted as it was implicitly reparented to the QScrollArea when set.

                Just create horizontalLayout without a parent, set it as layout to an ordinary QWidget instead of a QScrollArea (QGraphicsView already implements QAbstractScrollArea) and set this widget as the central widget.

                If there is anything you haven't understood - especially parenting or the layout system - you should have a good read on Qt fundamentals first. If there are any specific questions feel free to come back here.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  ananthbangali
                  wrote on last edited by
                  #8

                  Thanks a lot for your reply.... Yes, now I have modified my code and its working fine, now I can display two GraphicsView windows in the GUI. I have to work out on layouts,, I will definitely comeback if I have any queries. Thanks a ton :)

                  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