ÈÕÆÚ£º2011-03-22 13:54:00  À´Ô´£º±¾Õ¾ÕûÀí

Qtѧϰ֮·(32):Ò»¸ö¼òÒ×»­°åµÄʵÏÖ(Graphics View)[VC/C++±à³Ì]

ÔÞÖúÉÌÁ´½Ó



¡¡¡¡±¾ÎÄ¡°Qtѧϰ֮·(32):Ò»¸ö¼òÒ×»­°åµÄʵÏÖ(Graphics View)[VC/C++±à³Ì]¡±ÊÇÓÉÆßµÀÆæΪÄú¾«ÐÄÊÕ¼¯£¬À´Ô´ÓÚÍøÂçתÔØ£¬ÎÄÕ°æȨ¹éÎÄÕÂ×÷ÕßËùÓУ¬±¾Õ¾²»¶ÔÆä¹ÛµãÒÔ¼°ÄÚÈÝ×öÈκÎÆÀ¼Û£¬Çë¶ÁÕß×ÔÐÐÅжϣ¬ÒÔÏÂÊÇÆä¾ßÌåÄÚÈÝ£º

±¾ÎÄÅäÌ×Ô´Âë

ÕâÒ»´Î½«½éÉÜÈôºÎÀûÓÃGraphics ViewÀ´ÊµÏÖÇ°ÃæËù˵µÄ»­°å.Ç°Ãæ˵Á˺ܶàÓйØGraphics ViewµÄºÃ»°,µ«ÊÇûÓоßÌåµÄʵÀýºÜÄÑ˵±Ï¾¹ºÃÔÚÄDZß.Ä¿Ç°ÎÒÃǾͰÑÇ°ÃæµÄÄÚÈÝÀûÓÃGraphics ViewÖØÐÂʵÏÖÒ»ÏÂ,´ó¼Ò¿ÉÒԱȽÏһϿ´ÓÐʲô±æ±ð.

ͬǰÃæÀàËƵÄÄÚÈݾͲ»ÔÙÂÛÊöÁË,ÎÒÃÇ´ÓÉϴδúÂëµÄµ××ÓÉϾÙÐиÄÕý,ÒÔ±ã·ûºÏÎÒÃǵÄÐèÇó.Ê×ÏÈÀ´¿´MainWindowµÄ´úÂë:

mainwindow.cpp

#include¡¡"mainwindow.h"
MainWindow::MainWindow(QWidget¡¡*parent)
:¡¡QMainWindow(parent)
{
¡¡QToolBar¡¡*bar¡¡=¡¡this->addToolBar("Tools");
¡¡QActionGroup¡¡*group¡¡=¡¡new¡¡QActionGroup(bar);
¡¡QAction¡¡*drawLineAction¡¡=¡¡new¡¡QAction("Line",¡¡bar);
¡¡drawLineAction->setIcon(QIcon(":/line.png"));
¡¡drawLineAction->setToolTip(tr("Draw¡¡a¡¡line."));
¡¡drawLineAction->setStatusTip(tr("Draw¡¡a¡¡line."));
¡¡drawLineAction->setCheckable(true);
¡¡drawLineAction->setChecked(true);
¡¡group->addAction(drawLineAction);
¡¡bar->addAction(drawLineAction);
¡¡QAction¡¡*drawRectAction¡¡=¡¡new¡¡QAction("Rectangle",¡¡bar);
¡¡drawRectAction->setIcon(QIcon(":/rect.png"));
¡¡drawRectAction->setToolTip(tr("Draw¡¡a¡¡rectangle."));
¡¡drawRectAction->setStatusTip(tr("Draw¡¡a¡¡rectangle."));
¡¡drawRectAction->setCheckable(true);
¡¡group->addAction(drawRectAction);
¡¡bar->addAction(drawRectAction);
¡¡QLabel¡¡*statusMsg¡¡=¡¡new¡¡QLabel;
¡¡statusBar()->addWidget(statusMsg);
¡¡PaintWidget¡¡*paintWidget¡¡=¡¡new¡¡PaintWidget(this);
¡¡QGraphicsView¡¡*view¡¡=¡¡new¡¡QGraphicsView(paintWidget,¡¡this);
¡¡setCentralWidget(view);
¡¡connect(drawLineAction,¡¡SIGNAL(triggered()), this,¡¡SLOT(drawLineActionTriggered()));
¡¡connect(drawRectAction,¡¡SIGNAL(triggered()), this,¡¡SLOT(drawRectActionTriggered()));
¡¡connect(this,¡¡SIGNAL(changeCurrentShape(Shape::Code)), paintWidget,¡¡SLOT(setCurrentShape(Shape::Code)));
}
void¡¡MainWindow::drawLineActionTriggered()
{
¡¡emit¡¡changeCurrentShape(Shape::Line);
}
void¡¡MainWindow::drawRectActionTriggered()
{
¡¡emit¡¡changeCurrentShape(Shape::Rect);
}

ÓÉÓÚmainwindow.hµÄ´úÂëÓëÇ°ÎÄÏàͬ,ÕâÀï¾Í²»ÔÙÌù³ö.¶øcppÎļþÀïÃæÖ»ÓÐÉÙÊý¼¸ÐÐÓëÇ°ÎIJî±ð.ÓÉÓÚÎÒÃÇÀûÓÃGraphics View,ËùÒÔ,ÎÒÃDZØÐë°ÑitemÔöÌíµ½QGprahicsSceneÀïÃæ.ÕâÀï,ÎÒÃdzÉÁ¢ÁËsceneµÄ¶ÔÏó,¶øscene¶ÔÏóÐèÇóͨ¹ýview¾ÙÐв쿴,Òò´Ë,ÎÒÃÇÐèÇóÔÙÀûÓÃÒ»¸öQGraphcisView¶ÔÏó,²¢ÇÒ°ÑÕâ¸öviewÔöÌíµ½MainWindowÀïÃæ.


¡¡¡¡ÒÔÉÏÊÇ¡°Qtѧϰ֮·(32):Ò»¸ö¼òÒ×»­°åµÄʵÏÖ(Graphics View)[VC/C++±à³Ì]¡±µÄÄÚÈÝ£¬Èç¹ûÄã¶ÔÒÔÉϸÃÎÄÕÂÄÚÈݸÐÐËȤ£¬Äã¿ÉÒÔ¿´¿´ÆßµÀÆæΪÄúÍƼöÒÔÏÂÎÄÕ£º

  • <b>Qtѧϰ֮·(28):×ø±ê±ä¸ü</b>
  • Qtѧϰ֮·(29):»­Í¼É豸
  • <b>Qtѧϰ֮·(30):Graphics View Framework</b>
  • <b>Qtѧϰ֮·(31):Ò»¸ö¼òÒ×»­°åµÄʵÏÖ(QWidget)</b>
  • Qtѧϰ֮·(32):Ò»¸ö¼òÒ×»­°åµÄʵÏÖ(Graphics View)
  • Qtѧϰ֮·(33):¹ú¼Ê»¯(ÉÏ)
  • <b>Qtѧϰ֮·(34):¹ú¼Ê»¯(ÏÂ)</b>
  • <b>Qtѧϰ֮·(9):ÉÀí½âÐźŲÛ</b>
  • Qtѧϰ֮·(10):Meta-Objectϵͳ
  • <b>Qtѧϰ֮·(11):MainWindow</b>
  • <b>Qtѧϰ֮·(12):²Ëµ¥ºÍ¹¤¾ßÌõ</b>
  • <b>Qtѧϰ֮·(13):²Ëµ¥ºÍ¹¤¾ßÌõ(Ðø)</b>
  • ±¾ÎĵØÖ·£º ÓëÄúµÄQQ/BBSºÃÓÑ·ÖÏí!
    • ºÃµÄÆÀ¼Û¡¡Èç¹ûÄú¾õµÃ´ËÎÄպ㬾ÍÇëÄú
        0%(0)
    • ²îµÄÆÀ¼Û¡¡Èç¹ûÄú¾õµÃ´ËÎÄÕ²¾ÍÇëÄú
        0%(0)

    ÎÄÕÂÆÀÂÛÆÀÂÛÄÚÈÝÖ»´ú±íÍøÓѹ۵㣬Óë±¾Õ¾Á¢³¡Î޹أ¡

       ÆÀÂÛÕªÒª(¹² 0 Ìõ£¬µÃ·Ö 0 ·Ö£¬Æ½¾ù 0 ·Ö) ²é¿´ÍêÕûÆÀÂÛ
    Copyright © 2020-2022 www.xiamiku.com. All Rights Reserved .