我有这样的形象:
我有一套改良产品(paintEvent(
)。
在我的形象之上,我想用一个或一个以上试金包 spare。 有了四舍五入的玉米和适当的反恐怖。
可在QPainter:CompositionMode 。 但情况如何? 可否将超支引向QImage? 无意中?
油漆:net 我在第二层中选取了一条直径,然后用魔.挑选内部,删除。 我不知道如何与QPainter打交道。
我有这样的形象:
我有一套改良产品(paintEvent(
)。
在我的形象之上,我想用一个或一个以上试金包 spare。 有了四舍五入的玉米和适当的反恐怖。
可在QPainter:CompositionMode 。 但情况如何? 可否将超支引向QImage? 无意中?
油漆:net 我在第二层中选取了一条直径,然后用魔.挑选内部,删除。 我不知道如何与QPainter打交道。
与组成模式合作是可能的,但需要完全了解他们的行为(奇怪的是,我从来没有能够把自己的头包起来)。
此外,在绘制地图时,它常常需要进一步的步骤,即把一个层推到一个临时的“ffer”(另一个QPixmap或QImage)。
As long as the "masking" is simple, it doesn t involve alpha blending of multiple images, and the image is opaque (no transparency at all), we could just follow a simpler path, which is painting over and eventually "clear" the required areas by clipping the contents.
The procedure is actually easy:
setClipPath()
on the QPainter (with the Antialiasing
render hint set);我不能在C++中写字,但以下简单的例子就足够清楚:
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
class ClipTest(QWidget):
def __init__(self):
super().__init__()
# This is the original image used in the question
self.pixmap = QPixmap( baseimage.png )
self.setFixedSize(self.pixmap.size())
def paintEvent(self, event):
qp = QPainter(self)
# draw the source image
qp.drawPixmap(0, 0, self.pixmap)
# draw the darker "shade" on the whole widget
qp.fillRect(self.rect(), QColor(32, 32, 32, 127))
path = QPainterPath()
# add a couple of rounded rects, which are also colliding
path.addRoundedRect(250, 110, 140, 140, 20, 20)
path.addRoundedRect(380, 110, 140, 140, 20, 20)
# to fill all enclosed regions, including those of colliding
# sub paths that may be otherwise be unpainted
path.setFillRule(Qt.WindingFill)
# clip the painting on the path above
qp.setClipPath(path)
# for proper antialiased clipping
qp.setRenderHint(qp.Antialiasing)
# redraw the pixmap again
qp.drawPixmap(0, 0, self.pixmap)
app = QApplication([])
win = Test()
win.show()
app.exec()
其结果如下:
I created an application for Windows in C++ using QT. If I want to port it to Linux or Mac OS, will sizeof(int) or sizeof(long) change? In other words, do types in QT applications for different ...
If I had a class A, where one of its functions does: void A::func() { emit first_signal(); emit second_signal(); } Assuming that a class B has 2 slots, one connected to first_signal, and the ...
I m using Qt and want a platform-independent way of getting the available free disk space. I know in Linux I can use statfs and in Windows I can use GetDiskFreeSpaceEx(). I know boost has a way, ...
I m working on a small project in QT (well, pyQT4 actually, but it shouldn t matter too much) and I ve run into the following problem. I have a QTableView with several rows and columns. I have set the ...
I m having big troubles with drag & drop. I ve created a new Qt Designer Form Class in which I have one QListWidget and one QWidget. Now I want to enable dragging & dropping between these two ...
I creating a small desktop application using Qt and Poco on Mac OS X Snow Leopard. Qt works fine, but once I started linking with Poco I get the following warning: ld: warning: in /Developer/SDKs/...
My friend and I have each created parts of a GUI using Qt 4. They both work independently and I am trying to integrate his form with the my main window. As of now this is the code I am using to try ...
Is there an equivalent of .NET s data binding in Qt? I want to populate some combo boxes and other widgets with QStrings that refer to specific entities in my database. However, it would be cleaner ...