search

Home  >  Q&A  >  body text

Pseudo elements in qt designer

I want to use a pseudo element to create a vertical line for the button on the left and dim it on hover, but qt-designer styleSheet doesn't understand me and it doesn't display correctly, here is my code:

QPushButton{
position: relative;
padding: 10px 20px;
border: none;
background-color: #fff;
color: #333;
cursor: pointer;
overflow: hidden;
}

QPushButton:before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 5px;
height: 100%;
background-color: #C6C6C6;
opacity: 0.5;
transition: all 0.3s ease-in-out;
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
}

QPushButton:hover:before {
background-color: #7F7F7F;
opacity: 0.8;
}

How does it look? Enter image description here as i wish Enter image description here

I tried rewriting it in a different way but I'm not very good at it

P粉600402085P粉600402085447 days ago574

reply all(1)I'll reply

  • P粉676588738

    P粉6765887382024-01-11 14:12:56

    Qt does not support CSS 3.0, but supports CSS 2.0. You need to modify your CSS to get what you want. The specific methods are as follows:

    QPushButton{
    position: relative;
    padding: 10px 20px;
    border: none;
    background-color: #fff;
    color: #333;
    cursor: pointer;
    overflow: hidden;
    }
    
    QPushButton:hover {
    width: 5px;
    height: 100%;
    border-left: 6px solid #7F7F7F;
    opacity: 0.5;
    border-top-right-radius: 4px;
    border-bottom-right-radius: 4px;
    
    opacity: 0.8;
    }

    reply
    0
  • Cancelreply