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
Related
I changed color of buttons using css, but when I move the mouse over them, buttons change their color to the default for a moment.
"button:hover" and "button:active" didn't help.
I used both:
background-image: image(black);
background-color: black;
And now it works great.
Using JavaFX when I create a TextField and set
numberField.setFocusTraversable(false);
and then click on the field the blue box shows up around it. I guess that makes sense
but there is no
setFocus(bool)
command.
I want to get rid of the box. Any suggestions?
The setFocusTraversable(false) disables the focus traversing (by TAB and SHIFT+TAB) for that node. Thus it has nothing related with node's GUI style. To hide the focused blue color do:
Via code
numberField.setStyle("-fx-focus-color: transparent;");
or via css file
.text-field {
-fx-focus-color: transparent;
}
or pseudo class in css file
.text-field:focused{
-fx-focus-color: transparent;
}
-fx-focus-color is not a css property, it is a predefined color of caspian.css (JavaFX 2).
This answer is related to and referenced from: How do I remove the default border glow of a JavaFX button (when selected)?.
I need a suggestion for making a QLabel to change as an editable comobox when user clicked it . similar like androidians.
i am planning to override the QLabel mousPress and show QComboBox while hiding the QLable.
is it right ..?
Your solution is correct. Another way you could do it is by using just a combo box and setting a stylesheet to it, so that the borders, the background and the arrow is hidden when it's not selected:
QComboBox:!focus{background-color: transparent; border: 0px;}
QComboBox::drop-down:!focus {border-width: 0px;}
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 am trying to achieve a borderless QLineEdit through CSS. It works fine when the QLineEdit is not in focus but when in focus the default blue border always comes up. The simple CSS I am using:
QLineEdit, QLineEdit:focus { border: none; }
I have tried with different background color through CSS for focus and not-in-focus, it works but I am unable to remove the blue border while in focus. Just to inform, I am working on a Mac.
You might get rid of the focus border by setting:
QLineEdit.setAttribute(Qt::WA_MacShowFocusRect, 0)
Read the documentation, there are plenty of other Mac specific settings
WidgetAttribute-enum
There is rather a similar question too
Refer this question
Maybe also like this way:
ui->treeView->setAttribute(Qt::WA_MacShowFocusRect, 0);
Reference: http://doc.qt.digia.com/4.6/demos-interview-main-cpp.html