// File: testGraphicItems.cpp
#include <QApplication>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QGraphicsRectItem>
#include <QGraphicsTextItem>
#include <ostream>
int main(int argc, char** argv)
{
// *******************************************
// *** Create Outer Parent QGraphicsItem ***
// *******************************************
outerParentItem->setToolTip ("Parent Item ToolTip");
myScene.addItem (outerParentItem);
// *******************************************
// *** Create Inner Parent QGraphicsItem ***
// *******************************************
// ************************************
// *** Create Child QGraphicsItem ***
// ************************************
const QRectF childRect
= childItem
->boundingRect
();
childItem->setPos (-0.5 * childRect.width(), -0.5 * childRect.height());
childItem->setToolTip ("Child Item ToolTip");
// ******************************
// *** Create QGraphicsView ***
// ******************************
myView.setCaption ("Test Nested QGraphicsItems ToolTips");
myView.setAttribute (Qt::WA_AlwaysShowToolTips);
myView.resize (420, 200);
myView.show();
return app.exec();
}
//--- (end testGraphicItems.cpp) ---
// File: testGraphicItems.cpp
#include <QApplication>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QGraphicsRectItem>
#include <QGraphicsTextItem>
#include <ostream>
int main(int argc, char** argv)
{
QApplication app (argc, argv);
QGraphicsScene myScene;
// *******************************************
// *** Create Outer Parent QGraphicsItem ***
// *******************************************
QGraphicsRectItem* outerParentItem =
new QGraphicsRectItem (-180.0, -70.0, 360.0, 140.0);
outerParentItem->setToolTip ("Parent Item ToolTip");
outerParentItem->setFlags (QGraphicsItem::ItemIsMovable |
QGraphicsItem::ItemIsSelectable);
myScene.addItem (outerParentItem);
// *******************************************
// *** Create Inner Parent QGraphicsItem ***
// *******************************************
QGraphicsRectItem* innerParentItem =
new QGraphicsRectItem (-140.0, -45.0, 280.0, 90.0, outerParentItem);
// ************************************
// *** Create Child QGraphicsItem ***
// ************************************
QGraphicsTextItem* childItem =
new QGraphicsTextItem ("Child QGraphicsTextItem", innerParentItem);
const QRectF childRect = childItem->boundingRect();
childItem->setPos (-0.5 * childRect.width(), -0.5 * childRect.height());
childItem->setToolTip ("Child Item ToolTip");
// ******************************
// *** Create QGraphicsView ***
// ******************************
QGraphicsView myView (&myScene);
myView.setCaption ("Test Nested QGraphicsItems ToolTips");
myView.setAttribute (Qt::WA_AlwaysShowToolTips);
myView.resize (420, 200);
myView.show();
return app.exec();
}
//--- (end testGraphicItems.cpp) ---
To copy to clipboard, switch view to plain text mode
Bookmarks