如何在PySide2中添加边框或设置透明的QLayout?

时间:2019-12-26 20:03:39

标签: python qt pyside2

我正在为Blender做插件,我正在使用PySide2。我能够删除窗口标题,而仅显示窗口的内容。我在QFrame中插入了动画gif,并更改了边框。问题是容器仍然显示其尖锐的边框。

是否可以更改QLayout样式? 我希望将角添加到QLayout或将其设置为透明而不是白色。

enter image description here

这是我的代码:

'use strict';

const apiBaseUrl = 'http://localhost:7071';

const connection = new signalR.HubConnectionBuilder()
    .withUrl(`${apiBaseUrl}/api`)
    .configureLogging(signalR.LogLevel.Information)
    .build();


console.log('connecting...');
connection.start()
    .then((response) => {
        console.log('connection established', response);
        createMessage(Math.random().toString(36).substr(2, 9), 'User', 'User message');
    })
    .catch(logError);




function logError(err) {
    console.error('Error establishing connection', err);
}




class App extends React.Component {
    constructor() {
        super()
        this.state = {
            messages: [{ messageID: 1111, sender: 'olduser', text: 'old message' }]
        }
    }




    componentDidMount() {


        this.setState({
            messages: [...this.state.messages,
                { messageID: 2222, sender: 'user1', text: 'text1' },
                { messageID: 6666, sender: 'user2', text: 'text2' }
            ]

        })

        connection.on('newMessage', function (message) {
            alert(message.sender);
            this.setState({
                messages: [...this.state.messages, { messageID: 77777, sender: 'user2', text: 'text2' }]
            })

        });


    }

    render() {
        return (
            <div className="app">
                <MessageList messages={this.state.messages} />
            </div>
        );
    }
}

function createMessage(msgID, sender, messageText) {

    return axios.post(`${apiBaseUrl}/api/messages`, {
        messageID: msgID,
        sender: sender,
        text: messageText
    }).then(resp => {
        console.log('message sent', messageText);
    });
}


class MessageList extends React.Component {
    render() {
        return (

            <ul className="message-list">
                {this.props.messages.map((message, index) => {
                    return (
                        // <li key={message.id} className="message">
                        //  <div>{message.message}</div>
                        <li key={message.messageID} className="message">
                            <div>{message.sender}</div>
                            <div>{message.text}</div>
                        </li>
                    )
                })}
            </ul>
        )
    }
}


ReactDOM.render(<App />, document.getElementById('root'));

1 个答案:

答案 0 :(得分:1)

您必须使窗口透明:

self.setAttribute(QtCore.Qt.WA_TranslucentBackground, True)
self.setStyleSheet("""
QWidget{
    background: transparent;
}
QFrame{
    border-style: solid;
    border-color: rgba(55, 55, 55, 255);
    border-width: 3px;
    border-radius: 30px;
    background-color: rgba(55, 55, 55, 255);
}
""")

注意:布局不是图形元素,因此无法使其透明,必须使容器透明。