mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QGraphicsTextItem>
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
setCentralWidget(view);
view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
view->setScene(scene);
aux = view->geometry(); // AFTER DEBUGGING THIS ROW: AUX = 640x480+0+0
}
void MainWindow::drawLine()
{
scene->addLine(0, 0, 100, 100);
}
MainWindow::~MainWindow()
{
delete ui;
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QGraphicsTextItem>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
scene = new QGraphicsScene;
view = new QGraphicsView;
setCentralWidget(view);
view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
view->setScene(scene);
aux = view->geometry(); // AFTER DEBUGGING THIS ROW: AUX = 640x480+0+0
}
void MainWindow::drawLine()
{
scene->addLine(0, 0, 100, 100);
}
MainWindow::~MainWindow()
{
delete ui;
}
To copy to clipboard, switch view to plain text mode
main.cpp
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
MainWindow w;
w.showMaximized();
w.drawLine(); // THE LINE WON'T START AT THE TOP LEFT CORNER
return a.exec();
}
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.showMaximized();
w.drawLine(); // THE LINE WON'T START AT THE TOP LEFT CORNER
return a.exec();
}
To copy to clipboard, switch view to plain text mode
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QGraphicsView>
#include <QGraphicsScene>
namespace Ui {
class MainWindow;
}
{
Q_OBJECT
private:
Ui::MainWindow *ui;
public:
explicit MainWindow
(QWidget *parent
= 0);
void drawLine();
~MainWindow();
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QGraphicsView>
#include <QGraphicsScene>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
private:
Ui::MainWindow *ui;
QGraphicsView *view;
QGraphicsScene *scene;
QRect aux;
public:
explicit MainWindow(QWidget *parent = 0);
void drawLine();
~MainWindow();
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
Bookmarks