-
UID:81635
-
- 注册时间2009-07-03
- 最后登录2020-09-21
- 在线时间298小时
-
- 发帖571
- 搜Ta的帖子
- 精华0
- 金钱11122
- 威望594
- 贡献值18
- 好评度584
-
访问TA的空间加好友用道具
|
here is an example of using Qt Style Sheet: - Widget::Widget(QWidget *parent)
- : QWidget(parent)
- {
- // this->setMouseTracking(true);
- // qDebug()<<this->hasMouseTracking();
- m_timer = new QTimer(this);
- m_timer->start(10000);
- connect(m_timer,SIGNAL(timeout()),this,SLOT(flashSlot()));
- m_btn = new QPushButton(this);
- m_btn->setFixedSize(280,260);
- setStyleSheet("QPushButton{margin:0px 10px 20px 30px;" //top right bottom left
- "border:10px solid silver;"
- "border-style: outset;"
- "border-radius: 10px;"
- "padding:5px;"
- "background-color:gray;"
- "background-image:url(../1.jpg);"
- "background-position:top right;"
- "background-origin:content;"
- "background-repeat:none;}"
- "QPushButton:pressed {"
- "background-color: green;"
- "border-style: inset;"
- "}");
- m_btn->setMouseTracking(true);
- m_btn->show();
- }
- void Widget::flashSlot() //to set the random color of the button;
- {
- m_timer->stop();
- m_timer->start(200);
- int r,g,b;
- QString color,stR,stG,stB;
- qsrand(QTime(0,0,0).msecsTo(QTime::currentTime()));
- r = rand() % 256;
- g = rand() % 256;
- b = rand() % 256;
- bool ok = true;
- stR.setNum(r,16);if(stR.toInt(&ok,16)<16){stR.prepend("0");}
- stG.setNum(g,16);if(stG.toInt(&ok,16)<16){stG.prepend("0");}
- stB.setNum(b,16);if(stB.toInt(&ok,16)<16){stB.prepend("0");}
- color.append("#"+stR+stG+stB);
- int r0,g0,b0;
- QString color0,stR0,stG0,stB0;
- qsrand(QTime(0,0,0).msecsTo(QTime::currentTime()));
- r0 = (r+rand()) % 256;
- g0 = (g+rand()) % 256;
- b0 = (b+rand()) % 256;
- stR0.setNum(r0,16);if(stR0.toInt(&ok,16)<16){stR0.prepend("0");}
- stG0.setNum(g0,16);if(stG0.toInt(&ok,16)<16){stG0.prepend("0");}
- stB0.setNum(b0,16);if(stB0.toInt(&ok,16)<16){stB0.prepend("0");}
- color0.append("#"+stR0+stG0+stB0);
- m_btn->setStyleSheet(QString("background-color:%1;border-color:%2;").arg(color,color0));
- }
- void Widget::mouseMoveEvent(QMouseEvent *e)
- {
- // QRect rect(500,500,100,100);
- QRect rect(50,50,100,100);
- if(rect.contains(e->pos()))
- {
- this->setCursor(Qt::OpenHandCursor);
- }
- else
- {
- this->setCursor(Qt::ArrowCursor);
- }
- QWidget::mouseMoveEvent(e);
- }
underside here.rar (13 K) 下载次数:38 are the files of this example.hope that they can help you. [ 此帖被午小夜在2009-10-30 00:03重新编辑 ]
|