I have a label in my main window that displays some text. I also have a background image in the main window that needs to show through the label. Only the background and the text should be visible.
I've set the alpha to zero with a white label background following the instructions I found on SO (here and here).
label->setStyleSheet("background-color: rgba(255, 255, 255, 0);");
However, I still see a dark box.
You should set your main window transparent by adding these to the constructor of your main window :
setAttribute(Qt::WA_NoSystemBackground);
setAttribute(Qt::WA_TranslucentBackground);
You can also create a borderless dialog by setting Qt::FramelessWindowHint window flag :
setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
Related
I created a pushbutton in front of a video (use QVideoWidget and QMediaPlayer). I am using an image with a transparent background to set image button.
How can I set a QPushbutton to be transparent, but the image inside to be visible? I have tried setting it transparent, but the image's background turns black.
I have tried this C++ over Qt : Controlling transparency of Labels and Buttons but it doesn't work. And I tried this :
ui->btn_Touchme->setAttribute(Qt::WA_TranslucentBackground);
ui->btn_Touchme->setStyleSheet("QPushButton{background: transparent;}");
ui->btn_Touchme->setAttribute(Qt::WA_NoSystemBackground, true);
ui->btn_Touchme->setAttribute(Qt::WA_TranslucentBackground, true);
and it is still black
I tried using QLabel, but I got same result. Any suggestions for me?
I am using qt 5.3.2 and ubuntu 14.04LTS
If it is ok to show the button margin on mouse hover over the button, you can use a QToolButton with autoRaise set to true.
Also, you can set following stylesheet too to make button transparent even when mouse hovers over it.
ui->btn_Touchme->setStyleSheet("background-color: rgba(255, 255, 255, 0);");
In order to make a QPushButton transparent, you also need to set the button to be "flat":
button->setFlat(true);
button->setStyleSheet("QPushButton { background-color: transparent }");
Or in other words, set the border in the Stylesheet on 0px:
button->setStyleSheet("QPushButton { background-color: transparent; border: 0px }");
I hope this works for you and others that might have the same problem.
I am using Ubuntu 16.04 LTS Qt 5.7.0, and this works for me:
Change the stylesheet of the button in the .ui file:
border: 0px;
background: transparent; is not needed.
if you use qt designer. select the corresponding button and you have to change undermost of properties window "flat" set true; your css now works.
For me "background-color: rgba(255,255,255,0);border: 0px;" seems to work
I have a QMainWindow.
To that window, I've set a Central Widget.
I have a Vertical Box Layout, and have added some widgets to the Layout, including a QTableView.
I've set this Layout to the Central Widget and have set a Background colour for this widget.
Problem is..while the other widgets acquire this background colour, the TableView remains resolutely in White.
Could anyone please tell me how to resolve this?
You should use stylesheets in order to apply the background color to all widgets. The following will work:
*{
background-color: rgb(255,0,0);
alternate-background-color: rgb(0, 255, 0);
selection-background-color: rgb(0, 0, 255);
}
For more details check the Qt Style Sheet documentation and the StyleSheets reference. For examples have a look here
I guess you should try new the QWidget inherit from the Central Widget,that is:
QTableView* myTable = new QTableView(ui->centralWidget());
I have a QLabel, and I put an image on it using setpixmap(). That image has alpha channel.
The QLabel is on a QWidget which has a border-image specified by an image (so that the image is rescaled to fill the QWidget).
On the transparent parts of the QLabel, the result is not the image specified on the QWidget, but a gray color characteristic of "no color" Widget.
My question is how do I make this in such a way that the transparent part of the QLabel shows the border-image of the QWidget?
I've tried canceling autofillbackground, changing the background color of the QLabel to white transparent, but none helped.
You need to set the Widget Attributes and Window Flags appropriately:
Using QWidget::setAttribute() and Qt::WidgetAttribute...
Qt::WA_TranslucentBackground needs to be set to true.
Along with learning the Window Flags Example should help a lot.
If you are just looking for a single widget that paints a frameless image...
Here is a perfect example:
QSplashScreen Replacement
I am building an App in which I had given background to my mainWindow only and all other widgets are used without any background, but when I run the app they are not 100% transparent they are somewhat translucent, is there any way to make them 100 % transparent so that only foreground can appear with no background hint.
Could you post the code you are using to get transparancy at the moment? If you say that you get "something translucent" I think that you created a tool window which is not what you really want.
A really transparent main window could be achieved by removing the title bar (give the QWidget constructor Qt::FramelessWindowHint as second parameter - WindowFlags), draw everything in the widget that should be transparent in a uncommon color (like 255,0,255) and then cut it off.
A very primitive example of cutting off parts of a QWidget:
QBitmap b(100, 100);
b.fill(Qt::black);
setMask(b);
QBitmap must be black on that pixels that shall be visible and white on that are not. In this example just the 100,100 area starting at 0,0 will be visible, the rest of your window will be invisible.
I am having an image that is being used as an image map.Image map highlights as gray onclick.I want no highlightening.This doesnot happens on safari on mac.However, this happens only on ipad simulator/device.
use CSS on your images
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
it will set the highlight color to fully transparent (alpha 0) black making it not display if you will set alpha to 1.0 on the other hand you will make the highlight to fully cover the clickable area.
refer to Safari CSS Reference for more details