Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3490162
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:28:58+00:00 2026-05-18T11:28:58+00:00

I can add a QPixMapImage to a QGraphicsScene, but then I have two issues.

  • 0

I can add a QPixMapImage to a QGraphicsScene, but then I have two issues.

First I cannot create a pointer to my QPixmapItem declared in the header, where i can with QGraphicsScene.

I get an error “error: no matching function for call to ‘QGraphicsPixmapItem::QGraphicsPixmapItem(MainWindow* const)” … When I create my QGraphicsScene in Main the same way?

Second issue: I cannot move the QGraphicsPixmapItem around when the slider is moved (obv i won’t until the pointer is working). But can I even move it, or do i have to repaint it?

#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QtGui>
#include <QGraphicsView>
#include <QGraphicsPixmapItem>
#include <QPixmap>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    scene = new QGraphicsScene(this);
    QPixmap arrow = QPixmap::fromImage(QImage("ARROW.png"));
    arrowItem = new QGraphicsPixmapItem(this);
    arrowItem->setPixmap(arrow);
    ui->graphicsView->setScene(scene);
    ui->horizontalSlider->setMaximum(2000);

}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_horizontalSlider_sliderMoved(int position)
{
    arrowItem->setPos(position,position);
    scene->addItem(arrowItem);

}

Header:

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QGraphicsPixmapItem>

namespace Ui {
    class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private:
    Ui::MainWindow *ui;
    QGraphicsPixmapItem *arrowItem;
    QGraphicsScene *scene;

private slots:
    void on_horizontalSlider_sliderMoved(int position);
};

#endif // MAINWINDOW_H
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T11:28:58+00:00Added an answer on May 18, 2026 at 11:28 am

    Issue #1:

    There error you’re getting means there is no such constructor declared for QGraphicsPixmapItem; you use either one of these:

    QGraphicsPixmapItem(QGraphicsItem *parent = 0
    #ifndef Q_QDOC
                            // ### obsolete argument
                            , QGraphicsScene *scene = 0
    #endif
            );
        QGraphicsPixmapItem(const QPixmap &pixmap, QGraphicsItem *parent = 0
    #ifndef Q_QDOC
                            // ### obsolete argument
                            , QGraphicsScene *scene = 0
    #endif
            );
    

    Issue#2

    If I understood your question correctly you want to be able to drag your graphics items around the scene. You can switch this functionality on by using view->setDragMode method.

    Please see if an example below would work for you:

    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
        QGraphicsScene* scene = new QGraphicsScene(QRect(-50, -50, 400, 200));
    
        QPixmap image = QPixmap::fromImage(QImage("image.JPG"));
        QGraphicsPixmapItem* pixMapItem = new QGraphicsPixmapItem();
        pixMapItem->setPixmap(image);
        scene->addItem(pixMapItem);
    
        QGraphicsView* view = new QGraphicsView(ui->centralWidget);
        view->setScene(scene);
        view->setGeometry(QRect(50, 50, 400, 200));
        view->setDragMode(QGraphicsView::ScrollHandDrag);
        view->show();
    }
    

    hope this helps, regards

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can add two descriptions (attribute) using my IDE, but from Java I can
I can add and delete cells to my table view. How to have two
I can add a normal rightBarButton to my navigation without a problem but now
I can add a Conditional statement to a breakpoint, for instance arg0.startsWith(something) but i'd
I can add items to a listview this way: ListViewItem.Items.Add(Text) But how can I
I can add the table in the backend or the front end, but if
You can add product to compare. I have to show the link Add to
How can I add elements from two sets? If there's a set one (1,
I'm aware I can add maven repositories for fetching dependencies in ~/.m2/settings.xml. But is
How I can add Header params in restlet android? I have following code: ClientResource

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.