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;}
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 am using a Qstylesheet to control the behavior of some QPushButtons and QToolButtons. When I hover over them, they turn black, as I want them to. However, once I press them, they turn a funny greyish reddish color, and there is a red box drawn inside of them.
What is the property or pseudo state that I have to set in order to avoid this behavior? I have been through all the properties related to selection, and background, and cant get this to go away
Without seeing your style it's a little difficult to fix your problem. So what I'll do is explain a little how things work, and hopefully you can decide how best to address your problem.
First, it's important when your styling your button to ensure that you cover all your bases. I'm sure you know most of this, but just in case...
A QPushButton and QToolButton have a number of states that can be styled, so you want to make sure that you make your button noticeably different for each state so that the user can tell the difference.
QPushButton
{
// The default look of your button
}
QPushButton:disabled
{
}
QPushButton:pressed
{
}
QPushButton:focus
{
}
QPushButton:hover
{
}
QPushButton:checked
{
}
Use things like the background color, foreground color, border color, and generally you are good to go.
background-color: red;
color: white; // foreground color
border-width: 1px;
border-color: black;
The second thing to know is this, styles can be inherited. So be really careful when you add a style to a widget. When you create a style try to be specific. If you give this style to something in your UI, the background color will be blue, but the dangerous thing, is that all child widgets of this one will also inherit this style.
QWidget
{
background-color: blue;
}
Maybe that's what you want, but often not. So if you are styling buttons always put the QPushButton or QToolButton selector around them, the same should apply for other things you are styling too. So it's possible that's where your greyish reddish color is coming from.
Now, the last thing to know about styling buttons is the focus rectangle. It is the irritating dotted line that appears when your button has been focussed. See the picture below.
The unfortunate thing is that there is there is no way to style the focus rectangle using style sheets. But you can get rid of it, if that's what you want. See the following link:
Getting rid of the focus rectangle
So, in summary...
Make sure that your button style covers all the states that you
need.
Make sure that your button isn't influenced by any other
styles you have added to other widgets.
Either change, or get rid
of the focus rectangle as needed.
I hope that helps. If you want more specific help, then please post your style, and I'll take a look at it.
I have an horizontal QListView and I want to customize the checkbox and label inside with a stylesheet to put the label under the checkbox, not at the right side.
How can it be done?
I'm not sure if this will work in your case but I came looking for a similar thing (for QTreeWidget checkboxes) and found that this works:
tree_widget.setStyleSheet("QTreeView::indicator:checked { background:red; }");
I imagine the QListView would also have an indicator, but I can't test right now. Try this:
QListView::indicator {
subcontrol-position: top center;
}
QCheckBox::indicator {
subcontrol-position: top center;
}
will do the job. The solution is ugly but works. Not sure that it will work always - you may need to play with layout policies of QCheckBox or see whether you can preallocate enough space for it. Again - no promises. It worked on my test example with Qt 4.7.1
So the only solution is to create a styled item delegate with your custom checkbox and label, just adapt this code :
http://discussion.forum.nokia.com/forum/showthread.php?217027-Display-widget-as-items-in-a-QListView&p=813138&viewfull=1#post813138
I would like to be able to set the title bar in a jQuery dialog to transparent, I have seen the background being set to transparent but cant see anything on how to do the same to the title bar.
Set .ui-dialog .ui-dialog-titlebar {background-color:transparent}. You may also need to set .ui-dialog .ui-dialog-title {background-color:transparent}
I need to implement textbox with inplace button (for search or filter purposes). So, I need to get Qtoolbutton, that is flat and rendered as icon, and obtain the border when hovered by mouse or pressed. And maybe I'd add some almost transparent background on hover too.
I tried to set the following stylesheet:
'border: none; hover {border: 1px} pressed {border: 1px}'
, but it seems that only border set. Nothing happens when I hover or click it. I tried to set autoRaise() to True and False, I mean, maybe some intersection occured, but haven't succeed.
Furthermore, when button is placed in QlineEdit, if I set stylesheet to it, whole button vanishes, I cannot no border or icon or anything.
try putting ':' before 'hover', as well as 'pressed'