I want new form from 'OK' click after
From Mainwindow label Set image
image path : ./org/org.jpg
addim.h
private slots:
void on_buttonBox_accepted(); <---- 'OK' button
addim.cpp
void AddIm::on_ADdimg_cliekd()
system("raspistill -w 480 -h 360 -q 20 -o aaa.jpg -t 2");
QPixmap pix("./org/org.jpg);
ui2->QWidjet_org->setPixmap(pix); <--- QWidjet_org this label
I managed to do a minimal code that works:
MainWindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "dialog.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
public slots:
//This will change the image in the main window
void buttonHere();
//This will change the image in the dialog box
void buttonDialog();
private:
Ui::MainWindow *ui;
Dialog dialog;
//We need to save the image in QImage so it doesn't disappear
QImage image;
};
#endif // MAINWINDOW_H
MainWindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QObject::connect(ui->pushButton_here, SIGNAL(clicked(bool)), SLOT(buttonHere()));
QObject::connect(ui->pushButton_dialog, SIGNAL(clicked(bool)), SLOT(buttonDialog()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::buttonHere()
{
//We load the image
image.load(ui->label->text());
//We set the label image
ui->label_2->setPixmap(QPixmap::fromImage(image));
}
void MainWindow::buttonDialog()
{
//We call the function that changes the dialog image
dialog.setImage(ui->label->text());
//We show the dialog
dialog.show();
}
Dialog.h
#ifndef DIALOG_H
#define DIALOG_H
#include <QDialog>
namespace Ui {
class Dialog;
}
class Dialog : public QDialog
{
Q_OBJECT
public:
explicit Dialog(QWidget *parent = 0);
~Dialog();
//This function changes the image
void setImage(QString path);
private:
Ui::Dialog *ui;
//We need to save the image in QImage so it doesn't disappear
QImage image;
};
#endif // DIALOG_H
Dialog.cpp
#include "dialog.h"
#include "ui_dialog.h"
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
}
Dialog::~Dialog()
{
delete ui;
}
void Dialog::setImage(QString path)
{
//We load the image
image.load(path);
//We set the label image
ui->label->setPixmap(QPixmap::fromImage(image));
}
You get this result
http://i.imgur.com/sguOqLS.png
http://i.imgur.com/p2rCK9f.png
You should create a resource file, import your picture in it and then use the following example code:
QPixmap pixmap_btn_hw(":/new/myPrefix/btn_hardware.png");
QIcon ButtonIcon_hw(pixmap_btn_hw);
ui->hardware_btn->setIcon(ButtonIcon_hw);
ui->hardware_btn->setIconSize(pixmap_btn_hw.rect().size());
ui->hardware_btn->setFocusPolicy(Qt::NoFocus);
To start an external program, "sytem()" is a bad idea. The following is much better:
QProcess *prpr = new QProcess();
prpr->setProcessChannelMode(QProcess::MergedChannels);
prpr->start("raspistill -w 480 -h 360 -q 20 -o aaa.jpg -t 2");
if (!prpr->waitForFinished())
{
// there was an error
}
else
{
// command worked!
}
Related
This Project was going to drag a picture in frameless Widget, and print the coordinates.
create a Pro;
create paintEvent(), mousePressEvent(), mouseMoveEvent() inherited from Event in QWidget.
widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QPainter>
#include <QMouseEvent>
#include <QDebug>
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = nullptr);
~Widget();
private:
Ui::Widget *ui;
protected:
void paintEvent(QPaintEvent*);
void mousePressEvent(QMouseEvent *);
void mouseMoveEvent(QMouseEvent *);
private:
QPixmap pix; // drawing picture
QPoint pt; // globalPos() - this->frameGeometry().topLeft()
};
#endif // WIDGET_H
set Attributes of Widget, and print coordinates;
widget.cpp
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
pix.load("D:\\sun.png");
this->setWindowFlags(Qt::FramelessWindowHint);
this->setAttribute(Qt::WA_TranslucentBackground);
}
Widget::~Widget()
{
delete ui;
}
void Widget::paintEvent(QPaintEvent* ){
QPainter p(this);
p.drawPixmap(0,0,pix);
}
void Widget::mousePressEvent(QMouseEvent *ev){
if(ev->button()==Qt::LeftButton){
// pt=ev->globalPos() - this->frameGeometry().topLeft(); //it works, and mouse position wouldn't change
}else if(ev->button()==Qt::RightButton){
this->close();
}
}
void Widget::mouseMoveEvent(QMouseEvent *ev){
// this->move(ev->globalPos()-pt);
// qDebug()<<"POS:"<<ev->pos()<<"**GLOBAL:"<<ev->globalPos()<<"-"<<pt<<"**TopLeft: "<<this->geometry().topLeft();
// it works but the mouse's position will change after the mouseMoveEvent triggered.
// the mouse's position changed to geometry().topLeft()
this->move(ev->pos()+this->geometry().topLeft());
}
So, why did the position changed? what happened in the mouseMoveEvent(...)
I have 4 buttons on my main window. Each button opens its own window with its own data. How to identify the pressed button to open right window? For example: I press sales button and it opens a window that shows information about ticket sales.
Mainwindow ui
Here is my code from mainwindow h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <sales.h>
#include <theatres.h>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private slots:
void button_pressed();
private:
Ui::MainWindow *ui;
sales *s;
theatres *t;
};
#endif // MAINWINDOW_H
And here is my code from mainwindow cpp:
#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include "build/sqlite/sqlite3.h"
#include <QtSql/QSqlDatabase>
#include <QTableView>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect((*ui).pushButton,SIGNAL(released()), this, SLOT(button_pressed()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::button_pressed()
{
s = new sales(this);
s -> show();
}
As Andy Newman already answered
the shortest solution is a lambda function
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPushButton>
#include <QHBoxLayout>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QHBoxLayout *h_layout = new QHBoxLayout;
centralWidget()->setLayout(h_layout);
for(int c =1; c <= 10; c++)
{
QPushButton *button = new QPushButton(this); // create button
button->setText(QString::number(c)); // set button id
h_layout->addWidget(button); // add a button to the form
// lambda magic
/* connecting a button signal to a lambda function that captures a pointer to a
button and invokes an arbitrary type function. */
connect(button, &QPushButton::clicked, [this, button]() {
pressedButton(button->text());
});
}
}
void MainWindow::pressedButton(const QString &id_button)
{
qDebug("Pressed button: %ls", id_button.utf16());
}
MainWindow::~MainWindow()
{
delete ui;
}
#include "widget.h"
#include "./ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
connect(ui->btn_0,&QPushButton::clicked,this,&Widget::SlotButtonClicked);
connect(ui->btn_1,&QPushButton::clicked,this,&Widget::SlotButtonClicked);
connect(ui->btn_2,&QPushButton::clicked,this,&Widget::SlotButtonClicked);
connect(ui->btn_3,&QPushButton::clicked,this,&Widget::SlotButtonClicked);
}
Widget::~Widget()
{
delete ui;
}
void Widget::SlotButtonClicked()
{
auto sender = this->sender();
if ( sender == ui->btn_0 ) {
// Click btn_0 to open widget0
} else if ( sender == ui->btn_1 ) {
// Click btn_1 to open widget1
} else if ( sender == ui->btn_2 ) {
// Click btn_2 to open widget2
} else if ( sender == ui->btn_3 ) {
// Click btn_3 to open widget3
}
}
If you can use Qt Designer, the best way to do this is to click with button right on the QPushButton (On .ui file in Qt Designer) and click to "Go to Slot", this will create a private slot to this button! In the header file will create the definition, like this:
private slots:
void on_pushButton_clicked();
void on_pushButton_2_clicked();
void on_pushButton_3_clicked();
void on_pushButton_4_clicked();
And in the source file (.cpp) will create the "function" clicked pushButton:
void MainWindow::on_pushButton_clicked()
{
}
void MainWindow::on_pushButton_2_clicked()
{
}
void MainWindow::on_pushButton_3_clicked()
{
}
void MainWindow::on_pushButton_4_clicked()
{
}
Inside of the "function" in .cpp, you put the task that you want this button to do, in this case, to open a new window!
When you click "go to slot" in another button, will create another private slot with the respective number (If is the second QPushButton that you create, the private slot will be called by pushButton_2).
The usual way to do this would be to connect the 4 different buttons to 4 different slots. It looks like you are using QtDesigner so that shouldn't be an issue.
If you were generating an array of buttons at run time you'd run into problems and would need a different solution. You could try something like this to pass an array index to the function, for example:
connect(button[x], &QPushButton::clicked, this, [this, x]() { button_pressed(x); });
Or you could do it the Qt way, which would be to call ::setProperty to store data in the button, and then retrieve it from the event, but it's so esoteric that I can't actually remember how to do that...
I have a app that uses QMdiArea.
I want the text in the statusbar to update when another QMdiAreaSubwindow becomes active.
So the text in the statusbar should become the same as the Qlabel text inside the QWidget which is been displayed inside the QMdiAreaSubwindow.
But i can't find a way to do this. Right now the statusbar only shows the text from latest created QMdiAreaSubwindow. But it won't update the text in the statusbar(With qlabel from the qwidget) when another QMdiAreaSubwindow is selected.
As you can see in the screenshot, the text in the statusbar keeps saying "test2", but I want it to change to "text" from the active QMdiAreaSubwindow.
mainwindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QMdiArea>
#include <QMdiSubWindow>
#include <newwindow.h>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow();
void NewSubWindow(QString name);
void createStatusBar(QString name);
private slots:
void on_actionNew_triggered();
void on_mdiArea_subWindowActivated(QMdiSubWindow *arg1);
private:
Ui::MainWindow *ui;
NewWindow *nDialog;
};
#endif // MAINWINDOW_H
mainwindow.cpp:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "mdisubwidget.h"
#include "newwindow.h"
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
nDialog = new NewWindow();
connect(nDialog,&NewWindow::transmit,this,&MainWindow::NewSubWindow);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::NewSubWindow(QString name) {
// new Widget to add to mdiareasubwindow
mdisubwidget *mdiwidget = new mdisubwidget();
mdiwidget->addName(name);
mdiwidget->setWindowTitle(name);
// Create new mdiAreaSubWindow
ui->mdiArea->addSubWindow(mdiwidget);
// Show mdiArea
mdiwidget->show();
}
void MainWindow::on_actionNew_triggered()
{
nDialog->show();
}
void MainWindow::on_mdiArea_subWindowActivated(QMdiSubWindow *arg1)
{
mdisubwidget *mdiwidget = new mdisubwidget(arg1->widget());
qDebug() << "name" << mdiwidget->returnName();
createStatusBar(mdiwidget->returnName());
}
void MainWindow::createStatusBar(QString name)
{
statusBar()->showMessage("chart = "+name);
}
mdisubwidget.h
#ifndef MDISUBWIDGET_H
#define MDISUBWIDGET_H
#include <QWidget>
namespace Ui {
class mdisubwidget;
}
class mdisubwidget : public QWidget
{
Q_OBJECT
public:
explicit mdisubwidget(QWidget *parent = nullptr);
void addName(QString name);
QString returnName();
~mdisubwidget();
private:
Ui::mdisubwidget *ui;
};
#endif // MDISUBWIDGET_H
mdisubwidget.cpp
#include "mdisubwidget.h"
#include "ui_mdisubwidget.h"
#include "mainwindow.h"
QString currentName;
mdisubwidget::mdisubwidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::mdisubwidget)
{
ui->setupUi(this);
}
void mdisubwidget::addName(QString name) {
ui->label_2->setText(name);
currentName = name;
}
QString mdisubwidget::returnName() {
return currentName;
}
mdisubwidget::~mdisubwidget()
{
delete ui;
}
NewWindow.h:
#ifndef NEWWINDOW_H
#define NEWWINDOW_H
#include <QWidget>
namespace Ui {
class NewWindow;
}
class NewWindow : public QWidget
{
Q_OBJECT
public:
explicit NewWindow(QWidget *parent = nullptr);
~NewWindow();
signals:
void transmit(QString name);
private slots:
void on_pushButton_clicked();
private:
Ui::NewWindow *ui;
};
#endif // NEWWINDOW_H
NewWindow.cpp:
#include "newwindow.h"
#include "ui_newwindow.h"
#include "mainwindow.h"
NewWindow::NewWindow(QWidget *parent) :
QWidget(parent),
ui(new Ui::NewWindow)
{
ui->setupUi(this);
}
NewWindow::~NewWindow()
{
delete ui;
}
void NewWindow::on_pushButton_clicked()
{
QString name = ui->lineEdit->text();
emit transmit(name);
}
ok you're using Qt Designer to connect the signal of subWindowActivated to the slot of on_mdiArea_subWindowActivated of your MainWindow, double check with qDebug in your on_mdiArea_subWindowActivated function if the name of your selected sub window appears on the console as you tried to change your current mdi sub window so follow my code snippets to find your way:
connect(ui->mdiArea, &QMdiArea::subWindowActivated, this, &DesignerWindow::activeViewChanged);
activeViewChanged():
void DesignerWindow::activeViewChanged(QMdiSubWindow *activeSubWindow)
{
// checks if there is no active sub window defined or the number of subwindows
// are zero then return
if (!activeSubWindow)
return;
if (ui->mdiArea->subWindowList().count() == 0) {
ui->itemsTree->clear();
return;
}
// defines the current Midi, View and graphical Scene when current sub window changes
currentMidi = reinterpret_cast<MidiWindow*>(activeSubWindow->widget());
currentView = reinterpret_cast<HMIView*>(currentMidi->internalView());
currentScene = reinterpret_cast<HMIScene*>(currentMidi->internalScene());
ItemsToolBar::ItemType currentType = currentScene->itemType();
itemsToolBar->selectItemType(currentType);
// updates the widgets and labels in status bar related to current midi sub window
updateScale(currentView->zoomFactor() * 100);
updateSelected();
updateItemsTree();
updateRendererType();
}
for example for updating the label in the status bar that holds the zooming factor of the current mdiSubWindow I wrote the updateScale procedure as below:
void DesignerWindow::updateScale(double _scale)
{
scale = static_cast<int>(_scale);
scaleLbl->setText(QString("%1%").arg(scale));
}
and finally I've noticed that your creating a label in status bar every time that you try to update the text in it, please avoid such a procedure and create a QLabel object and add it to your status bar as a permanent widget like below:
scaleLbl = new QLabel(this);
scaleLbl->setFrameStyle(QFrame::Sunken | QFrame::Panel);
scaleLbl->setMinimumWidth(50);
statusBar()->addPermanentWidget(scaleLbl);
New to C++ and Qt as part of a research project (biology) and have been struggling with presumably some quite simple stuff. I'd really appreciate someone's help.
I'm working with a GUI for a pre-existing programme and I'm trying to transfer a QString variable from the QLineEdit of one of the windows (inputform), to the QLineEdit of a second window (output form).
The bit I'm stuck with is that I need the output form to appear, with it's LineEdit pre-populated, when I click a button on a third window (filedialog).
Problem:
At start up --> two windows appear: filedialog and inputform.
User enters data into inputform's QLineEdit
User presses 'transferButton' on filedialog window
On button press --> outputform appears, with a QLineEdit pre-populated with the user's data (from the inputform).
I assume the problem is of the getter/setter variety and my variable is probably going out of scope, but I've tried following lots of similar examples but can't make it work.
Thanks in advance.
Here's my code:
Main.cpp
#include "filedialog.h"
#include "inputform.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
FileDialog w;
InputForm w2;
w.show();
w2.show();
return a.exec();
}
filedialog.h
#ifndef FILEDIALOG_H
#define FILEDIALOG_H
#include <QDialog>
namespace Ui {
class FileDialog;
}
class FileDialog : public QDialog
{
Q_OBJECT
public:
explicit FileDialog(QWidget *parent = nullptr);
~FileDialog();
void setFileName();
QString getFileName();
private slots:
void on_transferButton_clicked();
private:
Ui::FileDialog *ui;
QString fileName;
};
#endif // FILEDIALOG_H
filedialog.ccp
#include "filedialog.h"
#include "ui_filedialog.h"
#include "inputform.h"
#include "ui_inputform.h"
#include "outputform.h"
#include "ui_outputform.h"
FileDialog::FileDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::FileDialog)
{
ui->setupUi(this);
}
FileDialog::~FileDialog()
{
delete ui;
}
void FileDialog::setFileName()
{
InputForm *inputform = new InputForm;
fileName = inputform->ui->inputLineEdit->text();
}
QString FileDialog::getFileName()
{
return fileName;
}
void FileDialog::on_transferButton_clicked()
{
setFileName();
OutPutForm *outputform = new OutPutForm;
outputform->ui->outputLineEdit->setText(getFileName());
outputform->show();
}
inputform.h
#ifndef INPUTFORM_H
#define INPUTFORM_H
#include <QWidget>
namespace Ui {
class InputForm;
}
class InputForm : public QWidget
{
Q_OBJECT
public:
explicit InputForm(QWidget *parent = nullptr);
~InputForm();
Ui::InputForm *ui;
};
#endif // INPUTFORM_H
inputform.ccp
#include "inputform.h"
#include "ui_inputform.h"
InputForm::InputForm(QWidget *parent) :
QWidget(parent),
ui(new Ui::InputForm)
{
ui->setupUi(this);
}
InputForm::~InputForm()
{
delete ui;
}
outputform.h
#ifndef OUTPUTFORM_H
#define OUTPUTFORM_H
#include <QWidget>
namespace Ui {
class OutPutForm;
}
class OutPutForm : public QWidget
{
Q_OBJECT
public:
explicit OutPutForm(QWidget *parent = nullptr);
~OutPutForm();
Ui::OutPutForm *ui;
};
#endif // OUTPUTFORM_H
outputform.ccp
#include "outputform.h"
#include "ui_outputform.h"
OutPutForm::OutPutForm(QWidget *parent) :
QWidget(parent),
ui(new Ui::OutPutForm)
{
ui->setupUi(this);
}
OutPutForm::~OutPutForm()
{
delete ui;
}
Thank you for your brief pointer.
After some playing around:
Setup mainwindow (or in my case main dialog window). Generate inputform instance, connect button to inputform.
FileDialog::FileDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::FileDialog)
{
ui->setupUi(this);
InputForm *inputForm = new InputForm;
connect(ui->transferButton,SIGNAL(clicked()),inputForm,SLOT(getLineEditTextFunc()));
inputForm->show();
}
FileDialog::~FileDialog()
{
delete ui;
}
void FileDialog::on_transferButton_clicked()
{
}
Then from the input form:
Define a function to get the input form's LineEdit text (fileName); and then also generate an output form and populate it's LineEdit with the fileName variable.
InputForm::InputForm(QWidget *parent) :
QWidget(parent),
ui(new Ui::InputForm)
{
ui->setupUi(this);
}
InputForm::~InputForm()
{
delete ui;
}
void InputForm::getLineEditTextFunc()
{
fileName = this->ui->inputLineEdit->text();
OutPutForm *outputform = new OutPutForm;
outputform->ui->outputLineEdit->setText(fileName);
outputform->show();
}
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
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