PyQT:旋转 QLabel 使其对角定位而不是水平定位 [英] PyQT: Rotate a QLabel so that it's positioned diagonally instead of horizontally

查看:45
本文介绍了PyQT:旋转 QLabel 使其对角定位而不是水平定位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 gui 空间非常紧张的触摸屏应用程序.我想稍微旋转 QLabel 以使其垂直或稍微偏移对角线.有什么建议么?我在 QLabel 界面上找不到任何相关内容.

I'm working on a touch screen app where gui space is very tight. I'd like to rotate a QLabel a bit so that it's either vertical, or offset at a diagonal a bit. Any suggestions? I couldn't find anything relevant on the QLabel interface.

非常感谢!

推荐答案

QLabel 不这样做.但是您可以轻松创建自己的包含一些文本的小部件:

QLabel does not do this. But you can easily create your own widget containing a bit of text:

class MyLabel(QtGui.QWidget):
    def paintEvent(self, event):
        painter = QtGui.QPainter(self)
        painter.setPen(QtCore.Qt.black)
        painter.translate(20, 100)
        painter.rotate(-90)
        painter.drawText(0, 0, "hellos")
        painter.end()

另一种选择是绘制一个 QGraphicsView,然后您可以自由地通过任何坐标变换映射真实的小部件(即 QLabel).

Another option is to draw a QGraphicsView, you then have the liberty to map real widgets (i.e. a QLabel) through any coordinate transformation.

这篇关于PyQT:旋转 QLabel 使其对角定位而不是水平定位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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