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. Method to Use The Pixmap Currently Visible Inside a QGraphicsScene/View in an Unrelated slot
Forum Updated to NodeBB v4.3 + New Features

Method to Use The Pixmap Currently Visible Inside a QGraphicsScene/View in an Unrelated slot

Scheduled Pinned Locked Moved Solved General and Desktop
16 Posts 2 Posters 4.3k 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.
  • B Offline
    B Offline
    brazz
    wrote on last edited by brazz
    #1

    I woud like to somehow gain access to the Pixmap currently displayed in my QGraphics view so that I may use QPixmap::scaled() with the scaled value corresponding to the value_changed() slot for a slider. I just can't seem to find a way to keep the Pixmap I once assigned to my GraphicsScene in scope, or another way to access it. Below was my attempt at using GraphicsView::scene() I am not entirely sure how to implement this method though, in my example it gives me an error message "QGraphicsSCene::QGraphicsScene(const QGraphicsScene&)" is private as well as use of deleted function "QgraphicsScene(constScene&)". Any idea how I would access the Pixmap currently displayed in my QGraphicsView Widget?

    code inside my slider_value_changed() slot

    QGraphicsScene graphicsScene = ui->PixmapView->scene();
    QGraphicsPixmapItem graphicsPixmapItem = graphicsScene.itemAt(0, 0);
    
    mrjjM 1 Reply Last reply
    0
    • B brazz

      I woud like to somehow gain access to the Pixmap currently displayed in my QGraphics view so that I may use QPixmap::scaled() with the scaled value corresponding to the value_changed() slot for a slider. I just can't seem to find a way to keep the Pixmap I once assigned to my GraphicsScene in scope, or another way to access it. Below was my attempt at using GraphicsView::scene() I am not entirely sure how to implement this method though, in my example it gives me an error message "QGraphicsSCene::QGraphicsScene(const QGraphicsScene&)" is private as well as use of deleted function "QgraphicsScene(constScene&)". Any idea how I would access the Pixmap currently displayed in my QGraphicsView Widget?

      code inside my slider_value_changed() slot

      QGraphicsScene graphicsScene = ui->PixmapView->scene();
      QGraphicsPixmapItem graphicsPixmapItem = graphicsScene.itemAt(0, 0);
      
      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @brazz said in Method to Use The Pixmap Currently Visible Inside a QGraphicsScene/View in an Unrelated slot:

      QGraphicsPixmapItem

      This seems to do it
      QPixmap QGraphicsPixmapItem::pixmap() const

      1 Reply Last reply
      0
      • B Offline
        B Offline
        brazz
        wrote on last edited by
        #3

        If I'm right in interpreting your code there's still the issue that I can't actually access the scene viewed inside the graphics view, and in turn the graphics item. So I can't use QGraphicsPixmapItem::pixmap() due to not having the original GraphicsPixmapItem in scope still. The line QGraphicsScene graphicsscene = ui->PixmapView->scene(); doesn't compile and spits out the errors above.

        mrjjM 1 Reply Last reply
        0
        • B brazz

          If I'm right in interpreting your code there's still the issue that I can't actually access the scene viewed inside the graphics view, and in turn the graphics item. So I can't use QGraphicsPixmapItem::pixmap() due to not having the original GraphicsPixmapItem in scope still. The line QGraphicsScene graphicsscene = ui->PixmapView->scene(); doesn't compile and spits out the errors above.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @brazz
          Oh, its private. I used it in a subclass so did not notice.
          Just keep the scene around then.

          B 1 Reply Last reply
          0
          • mrjjM mrjj

            @brazz
            Oh, its private. I used it in a subclass so did not notice.
            Just keep the scene around then.

            B Offline
            B Offline
            brazz
            wrote on last edited by
            #5

            @mrjj I'm just not sure how I would go about keeping the scene around because it will be out of scope in the slots I am accessing the pixmap/scene in. Essentially what happens is the user opens a file, the actionOpen triggered() slot creates the pixMap and adds it to the scene and the graphicsView widget. After that though I need to scale the original pixmap using QPixmap::Scaled() in a slider_value_changed() slot, and that slot does not have access to the scene or the orginal pixmap. One possiblity would be make a class with a static pixmap memeber variable. But I have no idea if this would work or what the syntax would look like. I have been trying this possiblity for a while now.

            mrjjM 1 Reply Last reply
            0
            • B brazz

              @mrjj I'm just not sure how I would go about keeping the scene around because it will be out of scope in the slots I am accessing the pixmap/scene in. Essentially what happens is the user opens a file, the actionOpen triggered() slot creates the pixMap and adds it to the scene and the graphicsView widget. After that though I need to scale the original pixmap using QPixmap::Scaled() in a slider_value_changed() slot, and that slot does not have access to the scene or the orginal pixmap. One possiblity would be make a class with a static pixmap memeber variable. But I have no idea if this would work or what the syntax would look like. I have been trying this possiblity for a while now.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #6

              Hi
              Im not sure why you cant make it a member of the class that has the slot.
              Like he does here.
              http://www.bogotobogo.com/Qt/Qt5_QGraphicsView_QGraphicsScene.php

              It is completely other class than where you create the scene?

              B 1 Reply Last reply
              1
              • mrjjM mrjj

                Hi
                Im not sure why you cant make it a member of the class that has the slot.
                Like he does here.
                http://www.bogotobogo.com/Qt/Qt5_QGraphicsView_QGraphicsScene.php

                It is completely other class than where you create the scene?

                B Offline
                B Offline
                brazz
                wrote on last edited by
                #7

                @mrjj If I use this line in each slot scene = new QGraphicsScene(this); will it be referring to the same scene everytime? I'm not entirely what "this" points to specifically in Qt.

                mrjjM 1 Reply Last reply
                0
                • B brazz

                  @mrjj If I use this line in each slot scene = new QGraphicsScene(this); will it be referring to the same scene everytime? I'm not entirely what "this" points to specifically in Qt.

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by mrjj
                  #8

                  @brazz
                  No no that would create a new one each time.
                  You just do it ONCE. Like he does in sample
                  ("this" is used as parent/owner)

                  class Dialog : public QDialog
                  {
                  private:
                      QGraphicsScene *scene; <<< define
                  
                  and then in constructor
                  Dialog::Dialog(QWidget *parent) :
                  {
                      scene = new QGraphicsScene(this); <<< set it to point to an instance
                  

                  Then in any slot in Dialog class, you can use the variable scene to access it

                  In your case QDialog is most likely QMainwindow but 100% same way.

                  B 1 Reply Last reply
                  1
                  • mrjjM mrjj

                    @brazz
                    No no that would create a new one each time.
                    You just do it ONCE. Like he does in sample
                    ("this" is used as parent/owner)

                    class Dialog : public QDialog
                    {
                    private:
                        QGraphicsScene *scene; <<< define
                    
                    and then in constructor
                    Dialog::Dialog(QWidget *parent) :
                    {
                        scene = new QGraphicsScene(this); <<< set it to point to an instance
                    

                    Then in any slot in Dialog class, you can use the variable scene to access it

                    In your case QDialog is most likely QMainwindow but 100% same way.

                    B Offline
                    B Offline
                    brazz
                    wrote on last edited by
                    #9

                    @mrjj Works perfectly, thank you. I figured it would have to do with adding code to the Qt auto generated stuff, I just didn't have to toolset/knowledge to do that yet. This trick will be make my life so much easier now.

                    mrjjM 1 Reply Last reply
                    0
                    • B brazz

                      @mrjj Works perfectly, thank you. I figured it would have to do with adding code to the Qt auto generated stuff, I just didn't have to toolset/knowledge to do that yet. This trick will be make my life so much easier now.

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by mrjj
                      #10

                      @brazz
                      Super. :)
                      Well adding code to any of the auto generated files is
                      not fun as they are overwritten
                      often. (like moc_xx files)

                      But the file the project wizard creates for you are for your use.
                      So that is fine to add code to. its never re-created again.

                      B 1 Reply Last reply
                      0
                      • mrjjM mrjj

                        @brazz
                        Super. :)
                        Well adding code to any of the auto generated files is
                        not fun as they are overwritten
                        often. (like moc_xx files)

                        But the file the project wizard creates for you are for your use.
                        So that is fine to add code to. its never re-created again.

                        B Offline
                        B Offline
                        brazz
                        wrote on last edited by
                        #11

                        @mrjj any idea why this bit of code says that the List is never used/declared

                        QList<QGraphicsItem*> graphicsItemList(wavesScene->items());
                           QGraphicsPixmapItem pixmapItem(graphicsItemList.at(0));
                        
                        mrjjM 1 Reply Last reply
                        0
                        • B brazz

                          @mrjj any idea why this bit of code says that the List is never used/declared

                          QList<QGraphicsItem*> graphicsItemList(wavesScene->items());
                             QGraphicsPixmapItem pixmapItem(graphicsItemList.at(0));
                          
                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by mrjj
                          #12

                          @brazz said in Method to Use The Pixmap Currently Visible Inside a QGraphicsScene/View in an Unrelated slot:

                          QList<QGraphicsItem*> graphicsItemList(wavesScene->items());
                          QGraphicsPixmapItem pixmapItem(graphicsItemList.at(0));

                          Ehh no as it's both declared and used.

                          What is the exact error ?
                          (you can right click and get it)

                          Same code in test project is not showing any warning.

                          also just to be sure u mean it
                          QGraphicsPixmapItem pixmapItem(graphicsItemList.at(0))
                          This makes a new QGraphicsPixmapItem (locally) and set
                          graphicsItemList.at(0) as parent.
                          Its not same as
                          QGraphicsPixmapItem *pixmapItem = graphicsItemList.at(0);
                          That would point to the first item in the list.

                          B 1 Reply Last reply
                          0
                          • mrjjM mrjj

                            @brazz said in Method to Use The Pixmap Currently Visible Inside a QGraphicsScene/View in an Unrelated slot:

                            QList<QGraphicsItem*> graphicsItemList(wavesScene->items());
                            QGraphicsPixmapItem pixmapItem(graphicsItemList.at(0));

                            Ehh no as it's both declared and used.

                            What is the exact error ?
                            (you can right click and get it)

                            Same code in test project is not showing any warning.

                            also just to be sure u mean it
                            QGraphicsPixmapItem pixmapItem(graphicsItemList.at(0))
                            This makes a new QGraphicsPixmapItem (locally) and set
                            graphicsItemList.at(0) as parent.
                            Its not same as
                            QGraphicsPixmapItem *pixmapItem = graphicsItemList.at(0);
                            That would point to the first item in the list.

                            B Offline
                            B Offline
                            brazz
                            wrote on last edited by
                            #13

                            @mrjj D:\SEGYView\segyview.cpp:209: error: 'graphicsItemList' was not declared in this scope
                            QGraphicsPixmapItem* pixmapItem = graphicsItemList.at(0);

                                                               ^
                            

                            I tried I did mean to use the line that you provided, however it still gave the same error

                            1 Reply Last reply
                            0
                            • B Offline
                              B Offline
                              brazz
                              wrote on last edited by
                              #14

                              this is how I added the first item in my actionOpen triggered() slot

                                      wavesScene->addItem(pixmapGraphicsItem);
                              
                                      ui->PixmapView->setScene(wavesScene);
                              
                              mrjjM 1 Reply Last reply
                              0
                              • B brazz

                                this is how I added the first item in my actionOpen triggered() slot

                                        wavesScene->addItem(pixmapGraphicsItem);
                                
                                        ui->PixmapView->setScene(wavesScene);
                                
                                mrjjM Offline
                                mrjjM Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on last edited by
                                #15

                                @brazz

                                D:\SEGYView\segyview.cpp:209: error: 'graphicsItemList' was not declared in this scope

                                but those two lines are RIGHT next to each other or ?

                                just like you show ?

                                QList<QGraphicsItem*> graphicsItemList(wavesScene->items());
                                QGraphicsPixmapItem pixmapItem(graphicsItemList.at(0));
                                
                                1 Reply Last reply
                                0
                                • B Offline
                                  B Offline
                                  brazz
                                  wrote on last edited by
                                  #16

                                  Exactly like that. Could it be that I'm missing some inclusions? I included <QGraphicsPixmapItem> <QList> <QGraphicsItem>

                                  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