void LineCbBox::paintEvent (QPaintEvent *event) { QStyleOption opt; opt.initFrom(this); QPainter painter(this); style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this); painter.save(); // painter.setRenderHint(QPainter::Antialiasing); QColor ContourColor = Qt::gray; if(!isEnabled()) ContourColor = Qt::lightGray; QRect r = event->rect(); // QRect g = rect(); painter.setBrush(Qt::NoBrush); painter.setBackgroundMode(Qt::TransparentMode); QPen LinePen(m_Color); LinePen.setStyle(getStyle(m_Style)); LinePen.setWidth(m_Width); painter.setPen(LinePen); painter.drawLine(r.left()+5, r.height()/2, r.width()-10, r.height()/2); // QPen ContourPen(ContourColor); // painter.setPen(ContourPen); // r.adjust(0,2,-1,-3); // painter.drawRoundRect(r,5,40); painter.restore(); }
//重画函数 void CDlgOptionItem::OnPaint() { CPaintDC dc(this); //获取位置 CRect rcRect; GetClientRect(&rcRect); //建立缓冲 CDC BufferDC; CBitmap BufferBmp; BufferDC.CreateCompatibleDC(&dc); BufferBmp.CreateCompatibleBitmap(&dc,rcRect.Width(),rcRect.Height()); BufferDC.SelectObject(&BufferBmp); //绘画背景 COLORREF crBackGround=CSkinWndObject::m_SkinAttribute.m_crBackGround; BufferDC.FillSolidRect(0,0,rcRect.Width(),TITLE_HEIGHT,crBackGround); //绘画上框 CBrush BackBrush(TITLE_GROUND_COLOR); CPen LinePen(PS_SOLID,1,CSkinWndObject::m_SkinAttribute.m_crInsideBorder); BufferDC.SelectObject(&LinePen); BufferDC.SelectObject(&BackBrush); BufferDC.RoundRect(0,0,rcRect.Width(),TITLE_HEIGHT+10,10,10); //绘画下框 BufferDC.FillSolidRect(0,TITLE_HEIGHT,rcRect.Width(),rcRect.Height()-TITLE_HEIGHT,crBackGround); BufferDC.SelectObject(GetStockObject(NULL_BRUSH)); BufferDC.RoundRect(0,0,rcRect.Width(),rcRect.Height(),10,10); //绘画标题 LPCTSTR pszTitle=GetTitleText(); CRect rcTitil(10,0,rcRect.Width()-20,TITLE_HEIGHT); BufferDC.SetBkMode(TRANSPARENT); BufferDC.SetTextColor(RGB(10,10,10)); BufferDC.SelectObject(CSkinAttribute::m_DefaultFont); BufferDC.DrawText(pszTitle,lstrlen(pszTitle),rcTitil,DT_END_ELLIPSIS|DT_VCENTER|DT_SINGLELINE); //绘画界面 dc.BitBlt(0,0,rcRect.Width(),rcRect.Height(),&BufferDC,0,0,SRCCOPY); //清理资源 BufferDC.DeleteDC(); LinePen.DeleteObject(); BackBrush.DeleteObject(); BufferBmp.DeleteObject(); return; }
//闪动椅子 bool __cdecl CTableFrame::FlashChair(WORD wTableID, WORD wChairID) { //获取桌子 ITableView * pITableView=GetTableArrayPtr(wTableID); if (pITableView==NULL) return false; //获取位置 CRect rcChair=m_TableResource.m_rcChair[wChairID]; //获取视图位置 int iTableRow=wTableID%m_iCountRow; int iTableLine=wTableID/m_iCountRow; int iXPos=iTableRow*m_TableResource.m_wWidth+m_iXExcursion; int iYPos=iTableLine*m_TableResource.m_wHeight-m_iCurrentPos; rcChair.OffsetRect(iXPos,iYPos); //定义参数 const int nFlashTimes=18,nStepWidth=4; const int nExpandPos=nFlashTimes*nStepWidth; rcChair.InflateRect(nExpandPos,nExpandPos); //循环绘画 UpdateWindow(); CDC * pDC=GetDC(); CPen LinePen(PS_SOLID,0,GetSysColor(COLOR_BTNHILIGHT)); CPen * pOldPen=pDC->SelectObject(&LinePen); pDC->SetROP2(R2_XORPEN); for (int nTimes=nFlashTimes;nTimes>=0;nTimes--) { pDC->MoveTo(rcChair.left,rcChair.top); pDC->LineTo(rcChair.right,rcChair.top); pDC->LineTo(rcChair.right,rcChair.bottom); pDC->LineTo(rcChair.left,rcChair.bottom); pDC->LineTo(rcChair.left,rcChair.top); Sleep((nFlashTimes-nTimes)*2); pDC->MoveTo(rcChair.left,rcChair.top); pDC->LineTo(rcChair.right,rcChair.top); pDC->LineTo(rcChair.right,rcChair.bottom); pDC->LineTo(rcChair.left,rcChair.bottom); pDC->LineTo(rcChair.left,rcChair.top); rcChair.DeflateRect(nStepWidth,nStepWidth); } pDC->SelectObject(pOldPen); ReleaseDC(pDC); return true; }
void LineDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { if (option.state & QStyle::State_Selected) painter->fillRect(option.rect, option.palette.highlight()); painter->save(); QPen LinePen(m_LineColor); LinePen.setStyle(GetStyle(m_LineStyle[index.row()])); LinePen.setWidth(m_LineWidth[index.row()]); painter->setPen(LinePen); // if (option.state & QStyle::State_Selected) painter->setBrush(option.palette.highlightedText()); // else painter->setBrush(QBrush(Qt::black)); painter->drawLine(option.rect.x()+3, option.rect.y() + option.rect.height()/2, option.rect.width()-6, option.rect.y() + option.rect.height()/2); painter->restore(); }
//绘制背景 void CListCtrlEx::DrawBkItem(CDC* pDC, int RowIndex,CRect Rect) { if(m_BkData.m_BkFillMode == MODE_FILL_IMG) FillRectByImage(pDC,m_BkData.m_Image,Rect); else if (m_BkData.m_BkFillMode == MODE_FILL_RGB) pDC->FillSolidRect(Rect,m_BkData.m_BkColor); if(m_CurrentSelectRow == RowIndex) { if(m_BkData.m_HeightFillMode == MODE_FILL_IMG) FillRectByImage(pDC,m_BkData.m_HeightImage,Rect); else if (m_BkData.m_HeightFillMode == MODE_FILL_RGB) pDC->FillSolidRect(Rect,m_BkData.m_HeightColor); } else if(m_OldSelectRow == RowIndex)//当传进来的row为原来选中的时候就将其显示为原来的颜色 { if (m_BkData.m_HeightFillMode == MODE_FILL_RGB) { sItemBkData ItemData; ItemData.m_BkColor = RGB(24,25,25); pDC->FillSolidRect(Rect,ItemData.m_BkColor); } } CPen LinePen(PS_SOLID,1,m_LineColor); CPen* OldPen=(CPen*)pDC->SelectObject(LinePen); if(m_VecDrawLine ) { pDC->MoveTo(Rect.right,Rect.top); pDC->LineTo(Rect.right,Rect.bottom); } if(m_HorDrawLine) { pDC->MoveTo(Rect.left, Rect.bottom); pDC->LineTo(Rect.right, Rect.bottom); } }
void LineButton::paintEvent ( QPaintEvent * event ) { QColor ContourColor = Qt::gray; if(isEnabled()) { if(isDown()) { ContourColor = Qt::darkGray; } else { ContourColor = Qt::gray; } } else { ContourColor = Qt::lightGray; } QRect r = rect(); QPainter painter(this); painter.setBrush(Qt::NoBrush); painter.setBackgroundMode(Qt::TransparentMode); QPen LinePen(m_Color); LinePen.setStyle(::GetStyle(m_Style)); LinePen.setWidth(m_Width); painter.setPen(LinePen); painter.drawLine(r.left()+5, r.height()/2, r.width()-10, r.height()/2); QPen ContourPen(ContourColor); painter.setPen(ContourPen); r.adjust(0,2,-1,-3); painter.drawRoundRect(r,5,40); }
//重画消息 void CTabCtrlLogon::OnPaint() { //变量定义 CPaintDC dc(this); CSkinWndAttribute * pSkinAttribute=CSkinDialog::GetSkinAttribute(); //绘画背景 CRect ClipRect,ClientRect; dc.GetClipBox(&ClipRect); dc.FillSolidRect(&ClipRect,pSkinAttribute->m_crBackGround); //设置 DC dc.SetBkMode(TRANSPARENT); dc.SelectObject(pSkinAttribute->GetDefaultFont()); //绘画边框 GetClientRect(&ClientRect); ClientRect.top+=18; dc.Draw3dRect(&ClientRect,pSkinAttribute->m_crInsideBorder,pSkinAttribute->m_crInsideBorder); //获取信息 TCITEM ItemInfo; TCHAR szBuffer[100]; memset(&ItemInfo,0,sizeof(ItemInfo)); ItemInfo.mask=TCIF_TEXT|TCIF_IMAGE; ItemInfo.pszText=szBuffer; ItemInfo.cchTextMax=sizeof(szBuffer); //绘画按钮 CRect rcItem; int iCursel=GetCurSel(); CPen LinePen(PS_SOLID,1,pSkinAttribute->m_crInsideBorder); CPen * pOldPen=dc.SelectObject(&LinePen); for (int i=0;i<GetItemCount();i++) { GetItem(i,&ItemInfo); GetItemRect(i,&rcItem); dc.FillSolidRect(&rcItem,pSkinAttribute->m_crBackGround); dc.MoveTo(rcItem.left,rcItem.bottom-1); dc.LineTo(rcItem.left,rcItem.top+2); dc.LineTo(rcItem.left+2,rcItem.top); dc.LineTo(rcItem.right-2,rcItem.top); dc.LineTo(rcItem.right,rcItem.top+2); dc.LineTo(rcItem.right,rcItem.bottom-1); if (iCursel!=i) { rcItem.top+=2; dc.MoveTo(rcItem.left,rcItem.bottom-1); dc.LineTo(rcItem.right,rcItem.bottom-1); dc.SetTextColor(pSkinAttribute->m_crControlTXColor); DrawText(dc,szBuffer,lstrlen(szBuffer),&rcItem,DT_VCENTER|DT_SINGLELINE|DT_CENTER); } else { rcItem.top+=3; dc.SetTextColor(SELECT_COLOR); DrawText(dc,szBuffer,lstrlen(szBuffer),&rcItem,DT_VCENTER|DT_SINGLELINE|DT_CENTER); } } //清理资源 dc.SelectObject(pOldPen); LinePen.DeleteObject(); return; }
//重画消息 VOID CSkinTabCtrl::OnPaint() { //变量定义 CPaintDC dc(this); //获取位置 CRect rcClient; GetClientRect(&rcClient); //绘画背景 CRect rcClip; dc.GetClipBox(&rcClip); dc.FillSolidRect(&rcClip,m_crBackGround); //设置 DC dc.SetBkMode(TRANSPARENT); dc.SelectObject(CSkinResourceManager::GetInstance()->GetDefaultFont()); //绘画边框 rcClient.top+=26; dc.Draw3dRect(&rcClient,m_crControlBorder,m_crControlBorder); //绘画按钮 CPen LinePen(PS_SOLID,1,m_crControlBorder); CPen * pOldPen=dc.SelectObject(&LinePen); for (INT i=0;i<GetItemCount();i++) { //变量定义 TCITEM ItemInfo; ZeroMemory(&ItemInfo,sizeof(ItemInfo)); //变量定义 TCHAR szBuffer[100]; ItemInfo.mask=TCIF_TEXT|TCIF_IMAGE; ItemInfo.pszText=szBuffer; ItemInfo.cchTextMax=sizeof(szBuffer); //获取信息 CRect rcItem; GetItem(i,&ItemInfo); GetItemRect(i,&rcItem); //填充背景 dc.FillSolidRect(&rcItem,m_crBackGround); //绘画边框 dc.MoveTo(rcItem.left,rcItem.bottom-1); dc.LineTo(rcItem.left,rcItem.top+2); dc.LineTo(rcItem.left+2,rcItem.top); dc.LineTo(rcItem.right-2,rcItem.top); dc.LineTo(rcItem.right,rcItem.top+2); dc.LineTo(rcItem.right,rcItem.bottom-1); //绘画边框 if (i!=GetCurSel()) { rcItem.top+=2; dc.SetTextColor(m_crTabText); dc.MoveTo(rcItem.left,rcItem.bottom-1); dc.LineTo(rcItem.right,rcItem.bottom-1); DrawText(dc,szBuffer,lstrlen(szBuffer),&rcItem,DT_VCENTER|DT_SINGLELINE|DT_CENTER); } else { rcItem.top+=3; dc.SetTextColor(m_crTabText); DrawText(dc,szBuffer,lstrlen(szBuffer),&rcItem,DT_VCENTER|DT_SINGLELINE|DT_CENTER); } } //清理资源 dc.SelectObject(pOldPen); LinePen.DeleteObject(); return; }