void Preview360::paintEvent(QPaintEvent *) { QBitmap bitmap(this->size()); QPainter painter(&bitmap); painter.fillRect(bitmap.rect(), Qt::white); painter.setBrush(QColor(0, 0, 0)); //填充一个以圆弧为4个角的矩形,使窗体的四个角变成圆弧 painter.drawRoundedRect(QRect(0, 2, this->width(), this->height()-2), 5, 5); //画出(0, 2) -> (2, 100)区域 painter.drawRoundedRect(QRect(20, 0, 120-20, 2), 2, 2); setMask(bitmap); }
m_pLabelBg0 = new QLabel(this); m_pLabelBg0->setPixmap(QPixmap(":/images/bg_bottom.png")); m_pLabelBg0->setGeometry(QRect(0, 2, this->width(), this->height()-2)); m_pLabelBg1 = new QLabel(this); m_pLabelBg1->setPixmap(QPixmap(":/images/bg_top.png")); m_pLabelBg1->setGeometry(QRect(0, 0, this->width(), this->height()));
m_pLabelBg1->raise();
QPixmap pixmap(QSize(this->width()*WINDOW_PAGE_COUNT, WINDOW_HEIGHT-2)); QPainter painter(&pixmap); for (int i = 0; i < WINDOW_PAGE_COUNT; i++) { painter.drawImage(QRect(WINDOW_WIDTH*i, 0, WINDOW_WIDTH, WINDOW_HEIGHT-2), QImage(tr(":/images/desktop_%1.jpg").arg(i))); } m_pLabelFgTotal = new QLabel(this); m_pLabelFgTotal->resize(pixmap.size()); m_pLabelFgTotal->setPixmap(pixmap); m_pLabelFgTotal->move(WINDOW_START_X, WINDOW_START_Y);
void CLabel::paintEvent(QPaintEvent *e) { QPainter painter(this); if (getMouseEnterFlag()) { paintWidget(50, &painter); } else if (getMousePressFlag()) { paintWidget(80, &painter); } QWidget::paintEvent(e); } void CLabel::paintWidget(int transparency, QPainter *device) { QPen pen(Qt::NoBrush, 1); device->setPen(pen); //渐变线 QLinearGradient linear(this->rect().topLeft(), this->rect().bottomLeft()); //设置前景色; //0:前景色; 0.5:中间色; 1:背景色; //transparency为透明度 linear.setColorAt(0, QColor(255, 255, 255, transparency)); QBrush brush(linear); device->setBrush(brush); device->drawRoundedRect(this->rect(), 2, 2); }
void CLabel::enterEvent(QEvent *e) { if (!getMousePressFlag()) { setMouseEnterFlag(true); } this->setCursor(Qt::PointingHandCursor); } void CLabel::leaveEvent(QEvent *e) { setMouseEnterFlag(false); } void CLabel::mousePressEvent(QMouseEvent *e) { if (e->button() == Qt::LeftButton) { setMousePressFlag(true); emit signalLabelPress(this); } }
this->setStyleSheet("QWidget {background:transparent;border:0px;color:white;font-weight:bold;font-size:16px;}");
QStringList nameList; //为了对齐,所以在文字后面加了空格 nameList << tr("360安全桌面 ") << tr("木马防火墙 ") << tr("360保镖 ") << tr("电脑门诊 "); for (int i = 0; i < WINDOW_BUTTON_COUNT; i++) { CLabel *label = new CLabel(this); label = new CLabel(this); label->resize(QSize(155, 45)); label->setPixmap(QPixmap(tr(":/images/btn_%1.png").arg(i))); label->setText(nameList.at(i)); label->move(8+i*170, 319); connect(label, SIGNAL(signalLabelPress(CLabel*)), this, SLOT(slotLabelButtonPress(CLabel*)));; connect(label, SIGNAL(signalLabelPress(CLabel*)), this, SLOT(slotChangeCurrentPage(CLabel*))); m_pLabelBtnArray[i] = label; } m_pLabelBtnArray[0]->setMousePressFlag(true);
for (int i = 0; i < WINDOW_BUTTON_COUNT; i++) { m_pLabelBtnArray[i]->raise(); }
void Preview360::slotLabelButtonPress(CLabel *label) { for (int i = 0; i < WINDOW_BUTTON_COUNT; i++) { if (label != m_pLabelBtnArray[i]) { m_pLabelBtnArray[i]->setMousePressFlag(false); } } }
下载地址:360新版特性界面