問題描述
好吧,我再次嘗試使用 Qt Creator 上的 Linux GUI 應(yīng)用程序,我在我的項(xiàng)目的 Qt 資源文件中添加了幾個(gè)圖像.我試圖在我的主窗口和其他窗口和對(duì)話框中擁有一個(gè)漂亮的背景.我使用的是樣式表選項(xiàng)(無編碼).
Well, I was again trying my hands on a Linux GUI app on Qt Creator, I added couple of images in a Qt resource file of my project. And I tried to have a nice background in my main window and other windows and dialogs. I was using from the stylesheets option (no coding).
我無法設(shè)置標(biāo)簽和按鈕的透明度級(jí)別.關(guān)于如何從 Qt Creator GUI 本身做到這一點(diǎn)的任何想法???
!我附上了我的應(yīng)用程序外觀的快照.
I am unable to set the transparency level of labels and pushbuttons. Any ideas on how to do it from Qt creator GUI itself ???
!I am attaching a snap of how my application looks.
推薦答案
可以通過設(shè)置樣式表來設(shè)置QLabel或者QPushbutton的透明度:
You can set transparency of QLabel or QPushbutton by setting the stylesheet :
ui->label->setStyleSheet("background-color: rgba(255, 255, 255, 0);");
ui->button->setStyleSheet("background-color: rgba(255, 255, 255, 0);");
您還可以在設(shè)計(jì)器中將 background-color: rgba(255, 255, 255, 0);
添加到小部件的 styleSheet 屬性中.
You can also add background-color: rgba(255, 255, 255, 0);
to the styleSheet property of the widget in the designer.
第四個(gè)參數(shù)是 alpha.您還可以通過將 alpha 設(shè)置為大于零的某個(gè)值來擁有半透明小部件:
The fourth parameter is alpha. You can also have semi-transparent widgets by setting alpha to some value more than zero :
ui->button->setStyleSheet("background-color: rgba(255, 255, 255, 50);");
這篇關(guān)于C++ over Qt:控制標(biāo)簽和按鈕的透明度的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!