QSplashScreen.setPixmap 将启动画面移回默认位置
QSplashScreen.setPixmap moves Splashscreen back to default position
我创建了一个 QSplashScreen with a QPixmap 并将其移动到我的第二台显示器(不是默认显示器)的中央:
class SplashScreen(QSplashScreen):
def __init__(self):
self._pixmap = QPixmap("test1.png")
super(SplashScreen, self).__init__(self._pixmap)
screen = 1
scr = qApp.desktop().screenGeometry(screen)
self.move(scr.center() - self.rect().center()) # move to second screen
我正在尝试向我的像素图中添加一些内容,同时显示 SplashScreen:
def drawSomething(self):
add = QPixmap('test2.png')
painter = QPainter(self._pixmap)
painter.drawPixmap(0,0, add)
#nothing happing so far
self.repaint() # nothing happening
self.setPixmap(self._pixmap) # changes shown, but moved back to default-screen
似乎用于创建 QSplashScreen 的 QPixmap 被复制了,不再是相同的引用,因此对此的更改没有直接影响。
此外,使用 setPixmap()
将 SplashScreen 移回默认监视器。
是否可以直接在启动画面的活动 QPixmap 上绘制或设置一个新的而不需要再次移动屏幕?
(使用 move-command 似乎不是一个好的选择,当你在短时间内快速重绘时 - 闪屏然后在两个显示器上闪烁)
用法示例:
app = QApplication([])
splash = SplashScreen()
splash.show()
splash.drawSomething()
exit(app.exec_())
您应该重新实现 drawContents 函数以在 QSplashScreen QPixmap 上执行绘画。
我终于成功地在 self
上使用 QPainter
重新实现了 paintEvent
:
def paintEvent(self, *args, **kwargs):
painter = QPainter(self)
pixmap = QPixmap('test2.png')
#self.setMask(pixmap.mask()) # optional for transparency painting
painter.drawPixmap(0,0, pixmap)
然而,重新实现 drawContents
funktion 也能正常工作:
def drawContents(self, painter):
painter.drawPixmap(0,0, QPixmap('test2.png'))
super(SplashScreen, self).drawContents(painter)
记得在你绘画之后调用 super,不要丢失 QSplashScreen 上 messages shown 的绘画。
The default implementation draws the message passed by showMessage().
我创建了一个 QSplashScreen with a QPixmap 并将其移动到我的第二台显示器(不是默认显示器)的中央:
class SplashScreen(QSplashScreen):
def __init__(self):
self._pixmap = QPixmap("test1.png")
super(SplashScreen, self).__init__(self._pixmap)
screen = 1
scr = qApp.desktop().screenGeometry(screen)
self.move(scr.center() - self.rect().center()) # move to second screen
我正在尝试向我的像素图中添加一些内容,同时显示 SplashScreen:
def drawSomething(self):
add = QPixmap('test2.png')
painter = QPainter(self._pixmap)
painter.drawPixmap(0,0, add)
#nothing happing so far
self.repaint() # nothing happening
self.setPixmap(self._pixmap) # changes shown, but moved back to default-screen
似乎用于创建 QSplashScreen 的 QPixmap 被复制了,不再是相同的引用,因此对此的更改没有直接影响。
此外,使用 setPixmap()
将 SplashScreen 移回默认监视器。
是否可以直接在启动画面的活动 QPixmap 上绘制或设置一个新的而不需要再次移动屏幕?
(使用 move-command 似乎不是一个好的选择,当你在短时间内快速重绘时 - 闪屏然后在两个显示器上闪烁)
用法示例:
app = QApplication([])
splash = SplashScreen()
splash.show()
splash.drawSomething()
exit(app.exec_())
您应该重新实现 drawContents 函数以在 QSplashScreen QPixmap 上执行绘画。
我终于成功地在 self
上使用 QPainter
重新实现了 paintEvent
:
def paintEvent(self, *args, **kwargs):
painter = QPainter(self)
pixmap = QPixmap('test2.png')
#self.setMask(pixmap.mask()) # optional for transparency painting
painter.drawPixmap(0,0, pixmap)
然而,重新实现 drawContents
funktion
def drawContents(self, painter):
painter.drawPixmap(0,0, QPixmap('test2.png'))
super(SplashScreen, self).drawContents(painter)
记得在你绘画之后调用 super,不要丢失 QSplashScreen 上 messages shown 的绘画。
The default implementation draws the message passed by showMessage().