I am bit busy right now, but will post the code soon.
I have created, using designer, a graphics view -> ui.gvChart
I also have a class containing m_scene and m_view:
{
Q_OBJECT
public :
~Chart();
View* m_view;
..........
}
{
m_view = dynamic_cast<View*>(v);
vSetScene();
vSetView();
}
void Chart::vSetView()
{
m_view->setScene(m_scene);
m_view->show();
//setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
}
void Chart::vSetScene()
{
m_scene->setSceneRect(0, 0, m_view->width(),m_view->height());
m_scene
->setBackgroundBrush
(QBrush(Qt
::gray));
}
class Chart: public QWidget
{
Q_OBJECT
public :
Chart(QGraphicsView*,QWidget* parent = 0);
~Chart();
View* m_view;
QGraphicsScene* m_scene;
..........
}
Chart::Chart( QGraphicsView* v,QWidget* parent): QWidget(parent)
{
m_view = dynamic_cast<View*>(v);
vSetScene();
vSetView();
}
void Chart::vSetView()
{
m_view->setScene(m_scene);
m_view->show();
//setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
}
void Chart::vSetScene()
{
m_scene = new QGraphicsScene(this);
m_scene->setItemIndexMethod(QGraphicsScene::BspTreeIndex);
m_scene->setSceneRect(0, 0, m_view->width(),m_view->height());
m_scene->setBackgroundBrush(QBrush(Qt::gray));
}
To copy to clipboard, switch view to plain text mode
Here is the View class:
{
public:
~View() {}
protected:
};
{
m_contextMenu
= new QMenu;
m_contextMenu
= new QMenu;
m_contextMenu->addAction(act);
m_contextMenu->exec(event->globalPos());
}
class View: public QGraphicsView
{
public:
View(QWidget* parent): QGraphicsView(parent) {}
~View() {}
protected:
void contextMenuEvent(QContextMenuEvent*);
};
void View::contextMenuEvent(QContextMenuEvent* event)
{
QMenu* m_contextMenu;
m_contextMenu = new QMenu;
QAction* act = new QAction(QIcon(""),tr("Buuuuu"),this);
m_contextMenu = new QMenu;
m_contextMenu->addAction(act);
m_contextMenu->exec(event->globalPos());
}
To copy to clipboard, switch view to plain text mode
In the main class I create the Chart class:
m_chart = new Chart(ui.gvChart,this);
m_chart = new Chart(ui.gvChart,this);
To copy to clipboard, switch view to plain text mode
That's about all. I have added contextMenu code(used here) to show main Window context menu and the context Menu appears, but not workin here.
Thanks in advance for help.
Maverick
P.S.
the code compiles, but crashes in the SetScene(...->setSceneRect);
Bookmarks