Feeding::Feeding(QWidget *parent) { QGraphicsScene * scene = new QGraphicsScene(NULL); scene->setSceneRect(0,0,600,480); setScene(scene); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setFixedSize(600,481); setFocusPolicy(Qt::NoFocus); basket = new Basket(this); scene->addItem(basket); basket->setPos(225,425); basket->setFlag(QGraphicsItem::ItemIsFocusable); basket->setFocus(); scene->setFocusItem(basket); scene->clearFocus(); QTimer * spawnTimer = new QTimer(this); QObject::connect(spawnTimer,SIGNAL(timeout()),this,SLOT(spawn())); int spawnTime = 1500 + (rand() % 501); spawnTimer->start(spawnTime); score = new scoreFood(); scene->addItem(score); scene->setBackgroundBrush(QBrush(QImage(":/feeding/backgroundPark1.png"))); }
PlayScene::PlayScene(){ //creat a scene QGraphicsScene *scene = new QGraphicsScene(); scene->setSceneRect(0,0,1024,768); scene->setBackgroundBrush(QBrush(QImage("D:/img/img/bg.png"))); //add a view QGraphicsView *view = new QGraphicsView(scene); view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); view->setFixedSize(1024,768); //add Rec Rec *rec = new Rec(); rec->setFlag(QGraphicsItem::ItemIsFocusable); rec->setFocus(); scene->addItem(rec); BlueHit *bluehit = new BlueHit(); scene->addItem(bluehit); bluehit->setPos(80,190); //QTimer *timer = new QTimer(); //QObject::connect(timer,SIGNAL(timeout()),bluehit,SLOT(create())); Drum *drum = new Drum(); scene->addItem(drum); drum->setPos(1000,250); //show the view view->show(); }
void MainWindow::drawTank() { QGraphicsScene* scene = new QGraphicsScene(); QGraphicsRectItem* item1 = new QGraphicsRectItem(0,60,20,300); item1->setBrush(QBrush(Qt::darkGreen)); item1->setPen(QPen(Qt::NoPen)); scene->addItem(item1); QGraphicsRectItem* item2 = new QGraphicsRectItem(320,60,20,300); item2->setBrush(QBrush(Qt::darkGreen)); item2->setPen(QPen(Qt::NoPen)); scene->addItem(item2); QGraphicsRectItem* item3 = new QGraphicsRectItem(20,340,300,20); item3->setBrush(QBrush(Qt::darkGreen)); item3->setPen(QPen(Qt::NoPen)); scene->addItem(item3); QGraphicsRectItem* item4 = new QGraphicsRectItem(20,340-280*(fluidHeight/tankHeight),300,280*(fluidHeight/tankHeight)); item4->setBrush(QBrush(Qt::darkBlue)); item4->setPen(QPen(Qt::NoPen)); scene->addItem(item4); ui->graphicsView->setScene(scene); }
ViewProfileDivider::ViewProfileDivider (QGraphicsScene &scene, QGraphicsView &view, int sceneWidth, int sceneHeight, int yCenter, bool isLowerBoundary) : QGraphicsRectItem (X_INITIAL, 0, PADDLE_WIDTH, PADDLE_HEIGHT), m_view (view), m_yCenter (yCenter), m_divider (0), m_shadedArea (0), m_sceneWidth (sceneWidth), m_sceneHeight (sceneHeight), m_isLowerBoundary (isLowerBoundary) { // Initial positions will not appear since they are overridden by setX // Paddle setVisible (true); setPen (QPen (DIVIDER_COLOR)); setBrush (QBrush (QColor (140, 255, 140))); setOpacity (1.0); scene.addItem (this); setFlags (QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemSendsGeometryChanges); setCursor (Qt::OpenHandCursor); setZValue (2.0); // Arrow on paddle m_arrow = new QGraphicsPolygonItem (this); // Shaded area m_shadedArea = new QGraphicsRectItem (X_INITIAL, 0, 0, sceneHeight - 1); m_shadedArea->setOpacity (SHADED_AREA_OPACITY); m_shadedArea->setBrush (QBrush (SHADED_AREA_COLOR)); m_shadedArea->setPen (Qt::NoPen); m_shadedArea->setZValue (0.0); scene.addItem (m_shadedArea); // Vertical divider. This is not made a child of the paddle since that will force the divider // to always be drawn above the paddle, rather than underneath the paddle as we want. Even setting // the z values will not succeed in drawing the divider under the paddle if they are child-parent. m_divider = new QGraphicsLineItem (X_INITIAL, -SLOP, X_INITIAL, 2 * SLOP + sceneHeight); m_divider->setPen (QPen (QBrush (DIVIDER_COLOR), DIVIDER_WIDTH)); m_divider->setZValue (1.0); scene.addItem (m_divider); }
int main(int argc, char **argv) { Q_INIT_RESOURCE(stickman); QApplication app(argc, argv); StickMan *stickMan = new StickMan; stickMan->setDrawSticks(false); QGraphicsTextItem *textItem = new QGraphicsTextItem(); textItem->setHtml("<font color=\"white\"><b>Stickman</b>" "<p>" "Tell the stickman what to do!" "</p>" "<p><i>" "<li>Press <font color=\"purple\">J</font> to make the stickman jump.</li>" "<li>Press <font color=\"purple\">D</font> to make the stickman dance.</li>" "<li>Press <font color=\"purple\">C</font> to make him chill out.</li>" "<li>When you are done, press <font color=\"purple\">Escape</font>.</li>" "</i></p>" "<p>If he is unlucky, the stickman will get struck by lightning, and never jump, dance or chill out again." "</p></font>"); qreal w = textItem->boundingRect().width(); QRectF stickManBoundingRect = stickMan->mapToScene(stickMan->boundingRect()).boundingRect(); textItem->setPos(-w / 2.0, stickManBoundingRect.bottom() + 25.0); QGraphicsScene scene; scene.addItem(stickMan); scene.addItem(textItem); scene.setBackgroundBrush(Qt::black); GraphicsView view; view.setRenderHints(QPainter::Antialiasing); view.setTransformationAnchor(QGraphicsView::NoAnchor); view.setScene(&scene); QRectF sceneRect = scene.sceneRect(); // making enough room in the scene for stickman to jump and die view.resize(sceneRect.width() + 100, sceneRect.height() + 100); view.setSceneRect(sceneRect); view.show(); view.setFocus(); LifeCycle cycle(stickMan, &view); cycle.setDeathAnimation(":/animations/dead.bin"); cycle.addActivity(":/animations/jumping.bin", Qt::Key_J); cycle.addActivity(":/animations/dancing.bin", Qt::Key_D); cycle.addActivity(":/animations/chilling.bin", Qt::Key_C); cycle.start(); return app.exec(); }
int main(int argc, char *argv[]) { QApplication app(argc, argv); // build data GVGraph *graph = new GVGraph("Graph"); NodeId nid1 = graph->addNode("Node1"); GraphId gid1 = graph->addGraph("SubGraph1"); NodeId nid2 = graph->addNode("Node2", gid1); NodeId nid3 = graph->addNode("Node3", gid1); EdgeId eid1 = graph->addEdge(nid1, nid2, "Edge1"); graph->setEdgeAttribute(eid1, "label", "Edge1"); EdgeId eid2 = graph->addEdge(nid2, nid3, "Edge2"); graph->setEdgeAttribute(eid2, "label", "Edge2"); EdgeId eid3 = graph->addEdge(nid1, nid3, "Edge3"); graph->setEdgeAttribute(eid3, "label", "Edge3"); graph->applyLayout(); if (argc > 1 && strcmp(argv[1], "--no-gui") == 0) { return 0; } // build ui QGraphicsView *view = new QGraphicsView; view->setRenderHint(QPainter::Antialiasing); QGraphicsScene *scene = new QGraphicsScene; view->setScene(scene); Q_FOREACH (const GVNodePair &pair, graph->gvNodes()) { const GVNode node = pair.second; QGraphicsItem *item = new GVNodeItem(node, 0); scene->addItem(item); } Q_FOREACH (const GVEdgePair &pair, graph->gvEdges()) { const GVEdge edge = pair.second; QGraphicsItem *item = new GVEdgeItem(edge, 0); scene->addItem(item); } Q_FOREACH (const GVSubGraphPair &pair, graph->gvSubGraphs()) { const GVSubGraph graph = pair.second; QGraphicsItem *item = new GVGraphItem(graph, 0); scene->addItem(item); } delete graph; graph = 0; view->show(); return app.exec(); }
void TetrisCup::drawOnScene(QGraphicsScene &_scene) { _scene.addItem(new QGraphicsRectItem(-1, -1, BRICK * m_width + 2, BRICK * m_height + 2)); for (int i = 0; i < m_content.getHeight(); ++i) for (int j = 0; j < m_content.getWidth(); j++) { if (m_content.getValue(j, i) == 1) { QGraphicsRectItem *rect = new QGraphicsRectItem(j * BRICK, i * BRICK, BRICK, BRICK); rect->setPen(QPen(QBrush(QColor(Qt::lightGray)), 1, Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin)); rect->setBrush(QBrush(QColor(Qt::darkGray))); _scene.addItem(rect); } } }
int main(int argc, char** argv) { QApplication qapp(argc, argv); KComponentData cd("graphicsview-test"); Calligra::Sheets::Part part; Calligra::Sheets::Doc doc(&part); part.setDocument(&doc); bool ok = doc.openUrl(QUrl("/home/marijn/kde/src/calligra/docs/oos_AMSAT-IARU_Link_Model.ods")); if (!ok) { qDebug() << "failed to load"; return 0; } QFont font(KoGlobal::defaultFont()); Calligra::Sheets::CanvasItem* canvas = new Calligra::Sheets::CanvasItem(&doc); QRect usedArea = canvas->activeSheet()->usedArea(true); QFontMetricsF fm(font, 0); QSizeF size(canvas->activeSheet()->columnPosition(usedArea.right()+3), canvas->activeSheet()->rowPosition(usedArea.bottom()+5)); canvas->setDocumentSize(size); size = canvas->zoomHandler()->documentToView(size); canvas->resize(size); canvas->setPos(0, 0); Calligra::Sheets::ColumnHeaderItem* columnHeader = static_cast<Calligra::Sheets::ColumnHeaderItem*>(canvas->columnHeader()); static_cast<QGraphicsWidget*>(columnHeader)->resize(size.width(), fm.height() + 3); columnHeader->setPos(0, -columnHeader->height()); Calligra::Sheets::RowHeaderItem* rowHeader = static_cast<Calligra::Sheets::RowHeaderItem*>(canvas->rowHeader()); static_cast<QGraphicsWidget*>(rowHeader)->resize(fm.width(QString::fromLatin1("99999")) + 3, size.height()); rowHeader->setPos(-rowHeader->width(), 0); columnHeader->toolChanged("PanTool"); rowHeader->toolChanged("PanTool"); QGraphicsScene scene; scene.addItem(canvas); scene.addItem(columnHeader); scene.addItem(rowHeader); QGraphicsView view(&scene); view.show(); qapp.exec(); }
int main(int argc, char *argv[]) { QApplication a(argc, argv); QGraphicsScene s; QGraphicsView v(&s); ChangingBackground background(256,256); s.addItem(&background); std::vector<boost::shared_ptr<TransparentSprite> > sprites; //Add multiple sprites { const double pi = boost::math::constants::pi<double>(); const int n_sprites = 10; const double midx = background.pixmap().width() / 2.0; const double midy = background.pixmap().height() / 2.0; const double ray = std::min(midx,midy) * 0.8; const double d_angle = 2.0 * pi / static_cast<double>(n_sprites); double angle = 0.0; for (int i=0; i!=n_sprites; ++i) { boost::shared_ptr<TransparentSprite> sprite( new TransparentSprite( 32, 32, 128 + (std::rand() % 128), 128 + (std::rand() % 128), 128 + (std::rand() % 128) ) ); const double x = midx + (std::sin(angle) * ray) - (sprite->pixmap().width() / 2); const double y = midy - (std::cos(angle) * ray) - (sprite->pixmap().height() / 2); sprite->setX(x); sprite->setY(y); sprite->setRect(background.pixmap().width(),background.pixmap().height()); s.addItem(sprite.get()); sprites.push_back(sprite); angle+=d_angle; } } v.show(); boost::shared_ptr<QTimer> timer(new QTimer(&s)); timer->connect(timer.get(), SIGNAL(timeout()), &s, SLOT(advance())); timer->start(50); return a.exec(); }
Kaqtoos::Kaqtoos() : QMainWindow(), downloadManager(this), isOAuthUserConnected(false) { oauthRequest = new KQOAuthRequest(); oauthManager = new KQOAuthManager(this); setupUi(); setupActions(); setupConnections(); publicXmlUrls << QString("http://api.kactoos.com/br/api/products/get-product-list/format/xml/oauth_consumer_key/%1/limit/30/orderby/new-products").arg(consumerKey) << QString("http://api.kactoos.com/br/api/products/get-product-list/format/xml/oauth_consumer_key/%1/limit/30/orderby/popular").arg(consumerKey) << QString("http://api.kactoos.com/br/api/products/get-product-list/format/xml/oauth_consumer_key/%1/limit/30/orderby/economic").arg(consumerKey); // start downloading downloadManager.append(publicXmlUrls); // NOTE: just for test QGraphicsScene *scene = new QGraphicsScene(); ProductItem *item = new ProductItem(); item->setImage("http://www.kactoos.com/libraries/thumb/?src=/images/products/5791_3556942391.jpg"); scene->addItem(item); allProductsView->setScene(scene); setWindowTitle(tr("KaQToos")); resize(QSize(600, 480)); }
//! [0] int main(int argc, char **argv) { QApplication app(argc, argv); qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); //! [0] //! [1] QGraphicsScene scene; scene.setSceneRect(-300, -300, 600, 600); //! [1] //! [2] scene.setItemIndexMethod(QGraphicsScene::NoIndex); //! [2] //! [3] for (int i = 0; i < MouseCount; ++i) { Mouse *mouse = new Mouse; mouse->setPos(::sin((i * 6.28) / MouseCount) * 200, ::cos((i * 6.28) / MouseCount) * 200); scene.addItem(mouse); } //! [3] //! [4] GraphicsView view(&scene); view.setRenderHint(QPainter::Antialiasing); view.setBackgroundBrush(QPixmap(":/images/cheese.jpg")); //! [4] //! [5] view.setCacheMode(QGraphicsView::CacheBackground); view.setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate); //! [5] //! [6] view.setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Colliding Mice")); view.showMaximized(); return app.exec(); }
int main(int argc, char *argv[]) { QApplication app(argc, argv); QWebView *web = new QWebView(); web->load(QUrl("http://www.developpez.com")); web->show(); QGraphicsScene scene; scene.setSceneRect(0 , 0, 1000, 800); QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget(); proxy->setWidget(web); scene.addItem(proxy); QTransform matrix; matrix.rotate(45, Qt::YAxis); proxy->setTransform(matrix); QGraphicsView view(&scene); view.show(); view.setWindowTitle("Ma premiere scene"); return app.exec(); }
int main(int argc, char *argv[]) { QApplication app(argc, argv); QGraphicsScene scene; scene.setSceneRect(-500, -500, 1000, 1000); scene.setItemIndexMethod(QGraphicsScene::NoIndex); Car *car = new Car(); scene.addItem(car); QGraphicsView view(&scene); view.setRenderHint(QPainter::Antialiasing); view.setBackgroundBrush(Qt::darkGray); view.setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Qt DBus Controlled Car")); view.resize(400, 300); view.show(); new CarInterfaceAdaptor(car); QDBusConnection connection = QDBusConnection::sessionBus(); connection.registerObject("/Car", car); connection.registerService("com.trolltech.CarExample"); return app.exec(); }
void tst_QGraphicsEffect::prepareGeometryChangeInvalidateCache() { MyGraphicsItem *item = new MyGraphicsItem; item->resize(200, 200); QGraphicsScene scene; scene.addItem(item); QGraphicsView view(&scene); if(PlatformQuirks::isAutoMaximizing()) view.showFullScreen(); else view.show(); QTest::qWaitForWindowShown(&view); QTRY_COMPARE(item->nbPaint, 1); item->nbPaint = 0; item->setGraphicsEffect(new QGraphicsDropShadowEffect); QTRY_COMPARE(item->nbPaint, 1); item->nbPaint = 0; item->resize(300, 300); QTRY_COMPARE(item->nbPaint, 1); item->nbPaint = 0; item->setPos(item->pos() + QPointF(10, 10)); QTest::qWait(50); QCOMPARE(item->nbPaint, 0); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { this->showMaximized(); setFocusPolicy(Qt::StrongFocus); ui->setupUi(this); createActions(); createToolBars(); QPixmap *pixmap = new QPixmap(100, 100); pixmap->fill(Qt::black); QGraphicsPixmapItem *pixmapItem = new QGraphicsPixmapItem(); QGraphicsScene *scene = new QGraphicsScene(0,0,100,100); // ui->viewport->setScene(scene); QPainter painter; painter.begin(pixmap); painter.setPen(QColor(0,255,0)); painter.drawLine(20,20,30,30); painter.setPen(QColor(255,0,0)); painter.drawEllipse(30,30,30,30); painter.end(); pixmapItem->setPixmap(*pixmap); scene->addItem(pixmapItem); ui->viewport->setScene(scene); ui->viewport->update(); }
int main(int argc, char *argv[]) { QApplication a(argc, argv); QGraphicsView* view; //create scene QGraphicsScene* scene; scene = new QGraphicsScene(); //create item myrect* item = new myrect(); //set the item focusable item->setFlag(QGraphicsItem::ItemIsFocusable); item->setFocus(); //add the item in the scene scene->addItem(item); //create view to visualize the scene view = new QGraphicsView(scene); //show the view view->show(); return a.exec(); }
int main(int argc, char *argv[]) { Q_INIT_RESOURCE(embeddeddialogs); QApplication app(argc, argv); QGraphicsScene scene; scene.setStickyFocus(true); const int gridSize = 10; for (int y = 0; y < gridSize; ++y) { for (int x = 0; x < gridSize; ++x) { CustomProxy *proxy = new CustomProxy(0, Qt::Window); proxy->setWidget(new EmbeddedDialog); QRectF rect = proxy->boundingRect(); proxy->setPos(x * rect.width() * 1.05, y * rect.height() * 1.05); proxy->setCacheMode(QGraphicsItem::DeviceCoordinateCache); scene.addItem(proxy); } } scene.setSceneRect(scene.itemsBoundingRect()); QGraphicsView view(&scene); view.scale(0.5, 0.5); view.setRenderHints(view.renderHints() | QPainter::Antialiasing | QPainter::SmoothPixmapTransform); view.setBackgroundBrush(QPixmap(":/No-Ones-Laughing-3.jpg")); view.setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate); view.show(); view.setWindowTitle("Embedded Dialogs Example"); return app.exec(); }
int main(int argc, char *argv[]) { QApplication a(argc, argv); QWidget w; QGraphicsView *view = new QGraphicsView; QGraphicsScene scene; view->setScene(&scene); SmileyItem *item = new SmileyItem; scene.addItem(item); item->setFlag(QGraphicsItem::ItemIsMovable); QSlider *slider = new QSlider(Qt::Horizontal); slider->setRange(0,100); slider->setValue(item->smileSize()); QObject::connect(slider, SIGNAL(valueChanged(int)), item, SLOT(setSmileSize(int))); QObject::connect(item, SIGNAL(smileSizeChanged(int)), slider, SLOT(setValue(int))); QVBoxLayout *l = new QVBoxLayout(&w); l->addWidget(view); l->addWidget(slider); view->setRenderHint(QPainter::Antialiasing); w.show(); w.resize(600,400); return a.exec(); }
void tst_QGraphicsEffect::inheritOpacity() { QGraphicsScene scene; QGraphicsRectItem *rectItem = new QGraphicsRectItem(0, 0, 10, 10); CustomItem *item = new CustomItem(0, 0, 10, 10, rectItem); scene.addItem(rectItem); item->setGraphicsEffect(new DeviceEffect); item->setPen(Qt::NoPen); item->setBrush(Qt::red); rectItem->setOpacity(0.5); QGraphicsView view(&scene); view.show(); QTest::qWaitForWindowShown(&view); QTRY_VERIFY(item->numRepaints >= 1); int numRepaints = item->numRepaints; rectItem->setOpacity(1); // item should have been rerendered due to opacity changing QTRY_VERIFY(item->numRepaints > numRepaints); }
int main(int argc, char *argv[]) { QApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true); QApplication a(argc, argv); const QString fileAbsPath = a.arguments().at(1); qDebug("Opening %s...", qPrintable(fileAbsPath)); QMediaPlayer p; p.setMedia(QMediaContent(QUrl(fileAbsPath))); QGraphicsVideoItem* item = new QGraphicsVideoItem; QGraphicsScene* scene = new QGraphicsScene; scene->addText("TEST"); p.setVideoOutput(item); scene->addItem(item); scene->addRect(0, 0, 100, 100, QPen(Qt::red), QBrush(Qt::red)); item->setPos(0, 0); //QImage image(1920, 1080, QImage::Format_ARGB32); //image.fill(Qt::blue); //QPainter painter(&image); //painter.setRenderHint(QPainter::Antialiasing); //scene->render(&painter); QGraphicsView view(scene); //view.scene()->addItem(item); view.setViewport(new QOpenGLWidget); view.show(); p.play(); return a.exec(); }
void tst_QGraphicsEffect::itemHasNoContents() { QGraphicsRectItem *parent = new QGraphicsRectItem; parent->setFlag(QGraphicsItem::ItemHasNoContents); MyGraphicsItem *child = new MyGraphicsItem; child->setParentItem(parent); child->resize(200, 200); QGraphicsScene scene; scene.addItem(parent); QGraphicsView view(&scene); view.show(); QTest::qWaitForWindowShown(&view); QTRY_COMPARE(child->nbPaint, 1); CustomEffect *effect = new CustomEffect; parent->setGraphicsEffect(effect); QTRY_COMPARE(effect->numRepaints, 1); for (int i = 0; i < 3; ++i) { effect->reset(); effect->update(); QTRY_COMPARE(effect->numRepaints, 1); } }
void tst_QGraphicsEffect::graphicsEffectUpdateShouldNotInvalidateGraphicsItemCache() { QGraphicsScene scene; MyGraphicsItem parent; parent.resize(200, 200); parent.setCacheMode(QGraphicsItem::ItemCoordinateCache); scene.addItem(&parent); QGraphicsView view(&scene); view.show(); QApplication::setActiveWindow(&view); QTest::qWaitForWindowShown(&view); QTRY_COMPARE(parent.nbPaint, 1); //we set an effect on the parent MyGraphicsEffect* opacityEffect = new MyGraphicsEffect(&parent); opacityEffect->update(); parent.setGraphicsEffect(opacityEffect); //flush the events QApplication::processEvents(); //new effect applied->repaint QCOMPARE(parent.nbPaint, 1); opacityEffect->update(); //flush the events QApplication::processEvents(); //A change to the effect shouldn't invalidate the graphicsitem's cache // => it shouldn't trigger a paint QCOMPARE(parent.nbPaint, 1); }
void Ut_MWidget::testShowHideSimple() { QGraphicsScene scene; QGraphicsView view(&scene); view.resize(500, 500); view.show(); scene.addItem(widget); widget->setGeometry(10, 10, 50, 50); widget->hide(); m_dummySlotCalled = false; connect(widget, SIGNAL(displayEntered()), this, SLOT(dummySlot())); widget->show(); QVERIFY(m_dummySlotCalled == true); disconnect(widget, SIGNAL(displayEntered()), this, SLOT(dummySlot())); m_dummySlotCalled = false; connect(widget, SIGNAL(displayExited()), this, SLOT(dummySlot())); widget->hide(); QVERIFY(m_dummySlotCalled == true); disconnect(widget, SIGNAL(displayExited()), this, SLOT(dummySlot())); /* displayEntered() should not be emitted when show() is called for an off-view widget */ widget->setGeometry(-500, -500, 50, 50); m_dummySlotCalled = false; connect(widget, SIGNAL(displayEntered()), this, SLOT(dummySlot())); widget->show(); QVERIFY(m_dummySlotCalled == false); disconnect(widget, SIGNAL(displayEntered()), this, SLOT(dummySlot())); }
// the main device method virtual void run() { if(!opened) { scene->addItem(item); // lock the image viewer img_view_mutex.lock(); // update the pixmap and unlock the image viewer show_image(); // open a window to show the QGraphicsScene view->show(); // set the flag to true opened = true; } else { if (img_view_mutex.try_lock()) { // a new thread! std::thread show_image_thread(&ImageViewerDevice::show_image, this); // leave it alone show_image_thread.detach(); } } }
void Ut_MWidget::testShowHidePropagation() { QGraphicsScene scene; QGraphicsView view(&scene); view.resize(500, 500); view.show(); MWidget* topLevel = new MWidget; MLayout *layout = new MLayout(topLevel); MLinearLayoutPolicy *policy = new MLinearLayoutPolicy(layout, Qt::Vertical); policy->addItem(widget); scene.addItem(topLevel); topLevel->setGeometry(10, 10, 50, 50); topLevel->hide(); m_dummySlotCalled = false; connect(widget, SIGNAL(displayEntered()), this, SLOT(dummySlot())); topLevel->show(); QVERIFY(m_dummySlotCalled == true); disconnect(widget, SIGNAL(displayEntered()), this, SLOT(dummySlot())); m_dummySlotCalled = false; connect(widget, SIGNAL(displayExited()), this, SLOT(dummySlot())); topLevel->hide(); QVERIFY(m_dummySlotCalled == true); disconnect(widget, SIGNAL(displayExited()), this, SLOT(dummySlot())); }
Overview::Overview(QWidget* parent) : QGraphicsView(parent), m_min_scale_level(0), m_scale_level(0) { setWindowTitle(tr("Overview")); setWindowFlags(Qt::Tool); setBackgroundBrush(Qt::darkGray); setBackgroundRole(QPalette::Window); setRenderHint(QPainter::SmoothPixmapTransform, true); setDragMode(ScrollHandDrag); setFrameStyle(NoFrame); // Create scene QGraphicsScene* scene = new QGraphicsScene(this); setScene(scene); m_pixmap = new QGraphicsPixmapItem; m_pixmap->setTransformationMode(Qt::SmoothTransformation); scene->addItem(m_pixmap); reset(); // Restore geometry QSettings settings; if (settings.contains("Overview/Geometry")) { restoreGeometry(settings.value("Overview/Geometry").toByteArray()); setMinimumSize(size()); } else { resize(400, 400); setMinimumSize(size()); } m_default = settings.value("Overview/Default", true).toBool(); }
//################################################################################################ //################################# PUBLIC ################################################# //################################################################################################ TnoteNameLabel::TnoteNameLabel(const QString& text, QWidget* parent) : QGraphicsView(parent), m_p2Time(0), m_strikeOut(0), m_blinking(0), m_questMark(0), m_stringNumber(0) { setMouseTracking(false); setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); // setFrameShape(QFrame::NoFrame); QGraphicsScene *scene = new QGraphicsScene(this); setScene(scene); m_textItem = new QGraphicsTextItem(); scene->addItem(m_textItem); scene->setSceneRect(geometry()); setText(text); m_bgColor = qApp->palette().base().color(); m_bgColor.setAlpha(220); setBackgroundColor(m_bgColor); }
void tst_QGraphicsEffect::childrenVisibilityShouldInvalidateCache() { QGraphicsScene scene; MyGraphicsItem parent; parent.resize(200, 200); QGraphicsWidget child(&parent); child.resize(200, 200); child.setVisible(false); scene.addItem(&parent); QGraphicsView view(&scene); view.show(); QApplication::setActiveWindow(&view); QTest::qWaitForWindowShown(&view); QTRY_COMPARE(parent.nbPaint, 1); //we set an effect on the parent parent.setGraphicsEffect(new QGraphicsDropShadowEffect(&parent)); //flush the events QApplication::processEvents(); //new effect applied->repaint QCOMPARE(parent.nbPaint, 2); child.setVisible(true); //flush the events QApplication::processEvents(); //a new child appears we need to redraw the effect. QCOMPARE(parent.nbPaint, 3); }
int main(int argc, char *argv[]) { QApplication a(argc, argv); QGraphicsScene scene; QGraphicsView view(&scene); view.setMinimumHeight(150); QGraphicsPixmapItem *item = new QGraphicsPixmapItem(QPixmap(":/img/qt-logo.jpg")); scene.addItem(item); QGraphicsRotation *rotation = new QGraphicsRotation(); rotation->setAxis(Qt::ZAxis); rotation->setOrigin(QVector3D(QPoint(item->boundingRect().width() / 2.0, item->boundingRect().height() / 2.0))); item->setTransformations(QList<QGraphicsTransform *>() << rotation); QPropertyAnimation *anim = new QPropertyAnimation(rotation, "angle"); anim->setDuration(5000); anim->setStartValue(0); anim->setEndValue(360); anim->start(QAbstractAnimation::DeleteWhenStopped); view.show(); return a.exec(); }
int main(int argc, char *argv[]) { QApplication a(argc, argv); Model model; // create a scene QGraphicsScene* scene = new QGraphicsScene(); // create an item to put into scene MovingBall* ball = new MovingBall(model.get_width()/2, model.get_height()/2); // make rect focusable // add item to scene scene->addItem(ball); View* view = new View(scene); view->show(); // MainWindow w; // w.setCentralWidget(view); // w.setFixedSize(model.get_width(), model.get_height()); // w.show(); return a.exec(); }