1、应用Qt的design加载图像ico

应用圆形警示灯ico图像填充QLabel控件,在design界面中选中label控件,在pixmap的属性下抉择不同的图片来填充。

这种填充办法有一个毛病,就是图像没有进行缩放,这样label控件的大小就会导致无奈齐全显示图像,这里个别依照图像的宽高来设定label尺寸属性。

这里程度和垂直策略都抉择Maximum,而后把minimumSize和MaximumSize都设置成图像大小。

2、应用setStyleSheet()函数来批改QLabel

setStyleSheet()函数能够用来批改控件的显示qss,能够间接调用该函数将Label控件设定成警示灯的显示模式。

min-width:     40px;     //最小宽度 40pxmin-height:    40px;     //最小高度 40pxmax-width:     40px;     //最大宽度 40px max-height:    40px;     //最大高度 40pxborder-radius: 20px;      //边框是圆角,半径20pxborder:1px solid black;  //边框1px,边框彩色background: red;        //背景是红色

这里设定宽度高度和圆角,将Label显示成圆形状态。

    const QString m_red_SheetStyle = "min-width: 40px; min-height: 40px;max-width:40px; max-height: 40px;border-radius: 20px; background:red";    const QString m_green_SheetStyle = "min-width: 40px; min-height: 40px;max-width:40px; max-height: 40px;border-radius: 20px; ;background:green";    const QString m_gray_SheetStyle = "min-width: 40px; min-height: 40px;max-width:40px; max-height: 40px;border-radius: 20px;  border:1px solid black;background:grey";    const QString m_yellow_SheetStyle = "min-width: 40px; min-height: 40px;max-width:40px; max-height: 40px;border-radius: 20px;  border:1px solid black;background:yellow";    ui->lab_LED_R->setStyleSheet(m_red_SheetStyle);// 红色圆形警示灯    ui->lab_LED_G->setStyleSheet(m_green_SheetStyle);//绿色圆形警示灯    ui->lab_LED_B->setStyleSheet(m_yellow_SheetStyle);//黄色圆形警示灯    ui->lab_LED_GR->setStyleSheet(m_gray_SheetStyle);//灰色圆形警示灯

这里只介绍了简略的setStyleSheet()函数利用,包含一些过渡,通明等成果都能够应用setStyleSheet()函数来进行设置,这里就不开展了。