具体QPushButton样式 [英] Specific QPushButton style

查看:547
本文介绍了具体QPushButton样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何自定义QPushButton或QToolButton的外观,看起来像elementaryos的网页buttons?





我真正想要的是特征图片的位置和文字的一面,也许if我很幸运,我也可以得到一个边框,但我不真的需要下面的标题描述:)
我可以做到只有StyleSheets,或者我有子类QPushButton / QAbstractButton /这样的东西?我已经在所有地方搜索,但没有发现这个级别的自定义没有像在固定地方绘画的东西,这是我<想要的。



编辑:
我真的想要一个解决方案,它会给我一个可自定义的按钮,而不是一个固定的图像,在

  MainWindowButton(QString(title),/ * opt * / QString(description),QImage(icon) 


解决方案

有很多方法可以工作。 / p>

您可能首先考虑尝试使用正则 QPushButton QVBoxLayout 就可以了。您可以添加三个 QLabels ;一个用于标题文本,一个用于标题文本,一个用于图像。一些CSS可能用于渲染按钮的背景图像的上下和更多的CSS风格的两个标签中的文本,并将图像放在第三个,但是你会发现,标签不向下移动该按钮被点击。



我认为最好的解决方案涉及直接绘画。你可以通过子分类 QWidget 并覆盖 paintEvent()来实现。



你可以实现这个没有子类,通过渲染上下状态到一个向上的状态, QImage 并使用CSS为它们设置QPush按钮样式。



这些方法也有很多组合。 / p>

How can I customize the look of a QPushButton or QToolButton to look something like elementaryos's webpage "buttons"?

All I really want is the characteristic image position and the text on it's side, maybe if i'm lucky i can also get a border like that, but i don't really need the little description below the title :) Can i do it only with StyleSheets, or do i have to subclass QPushButton/QAbstractButton/Something like that? I already searched everywhere but didn't found that level of customization without things like painting something in a fixed place, which is exactly what i don't want.

EDIT: I really would like a solution that would get me a customizable button, not a fixed image one, something in the tracks of

MainWindowButton(QString(title), /*opt*/QString(description), QImage(icon));

解决方案

There are a number of approaches that may work.

You might first consider trying to compose a solution with a normal QPushButton with a QVBoxLayout on it. You could add three QLabels; one for the title text, one for the caption text and one for the image. Some CSS could probably be used to render the background image of the button for up and down and more CSS to style the text in the two labels and position the image on the third but you would then find that the labels don't shift down when the button is clicked.

I think the best solution involves direct painting. You could do this by sub classing a QWidget and overriding the paintEvent(). Render everything for the up state and shift everything over and down a bit for the down state.

You could achieve this without sub classing by rendering the up and down states to a QImage and styling a QPushbutton with them using CSS.

There are a number of combinations of these approaches too.

这篇关于具体QPushButton样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆