2

我想让一些按钮看起来像你在 Skype 中看到的按钮。如何QPushButton使用自定义形状设置样式?我没有这样做的任何想法。所以我需要一些建议。例如,我希望我QPushButton看起来像这张图片

4

1 回答 1

3

You can use QT-Stylesheets to style a QPushButton whatever the way you like it to be. You can style the border-image property of the QPushButton, there is an example here explains just that. Go through documentation. Specially study css box-modal.

But your requirement can be fulfilled simply by setting following style sheet to your QPushButton. You have to prepare PNG images using an image editing software like GIMP, so the image will have a transparent background.

QPushButton#myPushButton
{
    background-color: transparent;
    background-image: url(":/transparent_image.png");
    background-repeat: none;    
    border: none;
}

Furthermore, you might want to style :hover and :pressed pseudo states as well by setting two additional images, so it will look more like a button in terms of its behavior.

QPushButton#myPushButton:hover
{
   background-image: url(":/transparent_image_hover.png");
}

QPushButton#myPushButton:pressed
{
   background-image: url(":/transparent_image_pressed.png");
}

I have virtually spoon-fed the answer for you, so keep in mind that it is necessary to be specific when looking for an answer. So people can help you with more focused answers.

于 2012-11-19T03:37:06.403 回答