this->setStyleSheet("background-color: yellow"); iLabel = new QLabel(this); iLabel->setStyleSheet("background-color: rgba(97%,80%,9%,50%)"); } 1. 2. 3. 4. 5. 6. 2)设置背景图片 MainWin::MainWin() { this->setStyleSheet("background-image:url(:/bmp/IMG_0345.JPG)"); iLabel...
// 1. 无边框QString borderNone="border:none";// 2. 设置边框的值需要有3个因子: 宽度,线形,颜色QString borderStyle="border:5px solid #999999;";// 3. 设置边框的圆角半径为:30pxQString borderRadius="border-radius:30px;";// 边框可以为各种组合样式ui.widget->setStyleSheet(borderStyle+borderR...
this->setObjectName("w2");this->setStyleSheet("#w2{background-color: rgb(0, 255, 0)}"); 2.setStyleSheet设置背景图片时,如果所在类没有父类,既是第一层widget时,则不会显示背景图片,替代方案: QPalette pal =this->palette(); pal.setBrush(QPalette::Background, QBrush(QPixmap("./pic/1.jpg...
void MainWindow::on_font_color_triggered()//字体颜色 { qDebug() << "setFontColor"; QColor color = QColorDialog::getColor(Qt::black,this,"选择要设置的字体颜色");//第一个是颜色对话框的初始值 textEdit->setTextColor(color); } 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13...
widget->setStyleSheet("border: 1px solid black;"); 设置按钮样式: button->setStyleSheet("QPushButton { background-color: blue; color: white; } QPushButton:hover { background-color: red; }"); 设置文本框样式: lineEdit->setStyleSheet("QLineEdit { background-color: gray; color: white; } QLin...
3. 使用setStyleSheet方法 你还可以使用setStyleSheet方法来设置窗体或控件的透明度。 setStyleSheet("background-color: rgba(255, 255, 255, 50);"); 这里,我们使用RGBA颜色模型,其中A(Alpha)用于设置透明度。 4. 使用setAttribute和setAutoFillBackground方法 ...
a. 使用setStyleSheet()方法来设置按钮的样式表,从而更改按钮的颜色。例如,可以使用以下代码将按钮的背景颜色设置为红色: 代码语言:txt 复制 ```cpp 代码语言:txt 复制 button->setStyleSheet("background-color: red;"); 代码语言:txt 复制 ``` b. 使用setPalette()方法来设置按钮的调色板,从而更改按钮的颜色。
widget->setStyleSheet("QWidget#wid{background-color: rgba(255,0,0,0.5);}"); widget->show(); rgba(255,0,0,0.5)中参数解释: r【read】 表示:红色,范围:0-255, g【green】表示:绿色,范围:0-255, b【blue】 表示:蓝色,范围:0-255, ...
1.Qss 的setStyleSheet设置背景图片 1.1background-image设置平铺或者居中 这种方法设置的要点是要将图片添加到qrc文件中,形成资源路径,然后在QT界面编辑或者程序代码中通过设置路径来实现背景图片设置。图片大小不能自适应控件大小。只能可以实现平铺或者居中显示。background-position:center;设置显示位置,background-repeat:...
label->setStyleSheet("background-color: transparent;"); 复制代码 使用透明背景色:可以使用QColor类中的setAlpha()函数来设置透明度。将背景色设置为具有透明度的颜色。QColor transparentColor(Qt::transparent); label->setAutoFillBackground(true); label->setPalette(transparentColor); 复制代码...