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

<b>Qtѧϰ֮·(27):Í»±äÌî³ä</b>[VC/C++±à³Ì]

ÔÞÖúÉÌÁ´½Ó



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

Ç°Ãæ˵ÁËÓйط´×ßÑùµÄÏà¹Ø֪ʶ,ÏÂÃæÀ´ËµÒ»ÏÂÍ»±ä.Í»±äÊÇ»­Í¼Öкܳ£¼ûµÄÒ»ÖÖ¹¦Ð§,¼òµ¥À´Ëµ¾ÍÊÇ¿ÉÒ԰Ѽ¸ÖÖÑÕÉ«»ìºÏÔÚһͬ,ÈÃËüÃÇ¿ÉÒÔ×ÔÈ»µØ¹ý¶É,¶ø²»ÊÇÒ»ÏÂ×Ó±ä³ÉÁíÒ»ÖÖÑÕÉ«.Í»±äµÄËã·¨¶Ô±È¸´ÔÓ,дµÃ²»ºÃµÄ»°Ð§ÂÊ»áºÜµÍ,ºÃÔںܶ໭ͼϵͳ¶¼ÄÚÖÃÁËÍ»±äµÄ¹¦Ð§,QtÒ²²»ÀýÍâ.Í»±äÆÕͨÊÇÓÃÔÚÌî³äÀïÃæµÄ,ËùÒÔ,Í»±äµÄÉèÖþÍÊÇÔÚQBrushÀïÃæ.

Qt¹©Ó¦ÁËÈýÖÖÍ»±ä»­Ë¢,±æ±ðÊÇÏßÐÔÍ»±ä(QLinearGradient)¡¢·øÉäÍ»±ä(QRadialGradient)¡¢½Ç¶ÈÍ»±ä(QConicalGradient).ÒÔÏÂͼËùʾ(ͼƬ³ö×ÔC++ GUI Programming with Qt4, 2nd Edition):

ÏÂÃæÎÒÃÇÀ´¿´Ò»ÏÂÏßÐÔÍ»±äQLinearGradientµÄÓ÷¨.

void¡¡PaintedWidget::paintEvent(QPaintEvent¡¡*event)
{
QPainter¡¡painter(this);
painter.setRenderHint(QPainter::Antialiasing,¡¡true);
QLinearGradient¡¡linearGradient(60,¡¡50,¡¡200,¡¡200);
linearGradient.setColorAt(0.2,¡¡Qt::white);
linearGradient.setColorAt(0.6,¡¡Qt::green);
linearGradient.setColorAt(1.0,¡¡Qt::black);
painter.setBrush(QBrush(linearGradient));
painter.drawEllipse(50,¡¡50,¡¡200,¡¡150);
}

ͬǰÃæÒ»Ñù,ÕâÀïÒ²½ö½ö¸ø³öÁËpaintEvent()º¯ÊýÀïÃæµÄ´úÂë.

Ê×ÏÈÎÒÃÇ·­¿ªÁË·´×ßÑù,È»ºó³ÉÁ¢Ò»¸öQLinearGradient¶ÔÏóʵÀý.QLinearGradient¹¹Ô캯ÊýÓÐËĸö²ÎÊý,±æ±ðÊÇx1, y1, x2, y2,¼´Í»±äµÄÆðʼµãºÍÖÕÖ¹µã.ÔÚÕâÀï,ÎÒÃÇ´Ó(60, 50)¿ªÊ¼Í»±ä,µ½(200, 200)Ö¹.

Í»±äµÄÑÕÉ«ÊÇÔÚsetColorAt()º¯ÊýÖÐÖ¸¶¨µÄ.ÏÂÃæÊÇÕâ¸öº¯ÊýµÄÇ©Ãû:

void¡¡QGradient::setColorAt¡¡(¡¡qreal¡¡position,¡¡const¡¡QColor¡¡&¡¡color¡¡)

ËüµÄÒâ˼ÊÇ°ÑpositionλÖõÄÑÕÉ«ÉèÖóÉcolor.´ËÖÐ,positionÊÇÒ»¸ö0 - 1Çø¼äµÄÊý×Ö.Ò²¾ÍÊÇ˵,positionÊÇÏà¹ØÓÚÎÒÃdzÉÁ¢Í»±ä¶ÔÏóʱ×öµÄÄǸöÆðʼµãºÍÖÕÖ¹µãÇø¼äµÄ.±È·½Õâ¸öÏßÐÔÍ»±ä,¾ÍÊÇ˵,ÔÚ´Ó(60, 50)µ½(200, 200)µÄÏ߶ÎÉÏ,ÔÚ0.2,Ò²¾ÍÎå·ÖÖ®Ò»´¦ÉèÖóɰ×É«,ÔÚ0.6Ò²¾ÍÊÇÎå·ÖÖ®Èý´¦ÉèÖóÉÂÌÉ«,ÔÚ1.0Ò²¾ÍÊÇÖյ㴦ÉèÖóɺÚÉ«.

ÔÚ³ÉÁ¢QBrushʱ,°ÑÕâ¸öÍ»±ä¶ÔÏó´«ËͽøÈ¥,¾ÍÊÇÎÒÃǵĺó¹ûÀ²:

ÄÇô,ÎÒÃÇÔõôÈÃÏ߶ÎÒ²ÊÇÍ»±äµÄÄØ?ÒªÖªµÀ,Ö±ÏßÊÇÓû­±Ê»æÖƵİ¡!ÕâÀï,¼ÙÈçÄãϸÐIJéÔÄÁËAPIÎĵµ¾Í»á·¢ÏÖ,QPenÊdzÐÊÜQBrush×÷Ϊ²ÎÊýµÄ.Ò²¾ÍÊÇ˵,Äã¿ÉÒÔ²Ù×ÝÒ»¸öQBrush³ÉÁ¢Ò»¸öQPen,ÕâÑù,QBrushÈ«²¿µÄÌî³äЧ¹û¶¼¿ÉÒÔÓÃÔÚ»­±ÊÉÏÁË!

void¡¡PaintedWidget::paintEvent(QPaintEvent¡¡*event)
{
QPainter¡¡painter(this);
painter.setRenderHint(QPainter::Antialiasing,¡¡true);
QLinearGradient¡¡linearGradient(60,¡¡50,¡¡200,¡¡200);
linearGradient.setColorAt(0.2,¡¡Qt::white);
linearGradient.setColorAt(0.6,¡¡Qt::green);
linearGradient.setColorAt(1.0,¡¡Qt::black);
painter.setPen(QPen(QBrush(linearGradient),¡¡5));
painter.drawLine(50,¡¡50,¡¡200,¡¡200);
}

¿´¿´ÎÒÃǵÄÍ»±äÏß°É!

³ö´¦:http://devbean.blog.51cto.com/448512/238168


¡¡¡¡ÒÔÉÏÊÇ¡°<b>Qtѧϰ֮·(27):Í»±äÌî³ä</b>[VC/C++±à³Ì]¡±µÄÄÚÈÝ£¬Èç¹ûÄã¶ÔÒÔÉϸÃÎÄÕÂÄÚÈݸÐÐËȤ£¬Äã¿ÉÒÔ¿´¿´ÆßµÀÆæΪÄúÍƼöÒÔÏÂÎÄÕ£º
  • <b>hostsÊÇʲô hostsÎļþÔÚʲôλÖà ÈôºÎ¸ÄÕýhosts</b>
  • <b>ÔÚ Windows 8 ÖÐÊÖ¶¯°²×°ÓïÑÔ°ü</b>
  • <b>Îå¸ö³£¼û PHPÊý¾Ý¿âÎÊÌâ</b>
  • WindowsÖÐAlt¼üµÄ12¸ö¸ßЧ¿ìËÙµÄÀûÓñ¾Áì½éÉÜ
  • <b>MySQL ORDER BY µÄʵÏÖ½âÎö</b>
  • <b>Ïê½âMySQL´æ´¢Àú³Ì²ÎÊýÓÐÈýÖÖ·¶Àý(in¡¢out¡¢inout)</b>
  • <b>Win8ϵͳ»Ö¸´³öÀ´¾­µäµÄ¿ªÊ¼²Ëµ¥µÄ°ì·¨</b>
  • <b>Win8ϵͳ»¨ÆÁÔõô°ì Win8ϵͳ»¨ÆÁµÄ°ìÀí°ì·¨</b>
  • <b>Windows 7ϵͳÏÂÎÞÏßÍø¿¨°²×°</b>
  • <b>Ϊʲô Linux²»ÐèÇóËéƬÕûÀí</b>
  • <b>Windows 8ÖÐɾ³ýÕË»§µÄ¼¸ÖÖ°ì·¨(ͼ)</b>
  • <b>½ÌÄãÈç°²ÔÚwin7ÏÂÅäÖ÷ÓÉÆ÷</b>
  • ±¾ÎĵØÖ·£º ÓëÄúµÄQQ/BBSºÃÓÑ·ÖÏí!
    • ºÃµÄÆÀ¼Û¡¡Èç¹ûÄú¾õµÃ´ËÎÄպ㬾ÍÇëÄú
        0%(0)
    • ²îµÄÆÀ¼Û¡¡Èç¹ûÄú¾õµÃ´ËÎÄÕ²¾ÍÇëÄú
        0%(0)

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

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