導航:首頁 > 編程語言 > pythonqpainter

pythonqpainter

發布時間:2022-10-21 13:09:20

python 在編輯器裡面顯示name error,直接在python和shell運行顯示正常

Q_UNUSED(event);
QPainter painter(this);
painter.setBackground(m_brush);
painter.eraseRect(rect());

㈡ PYTHON pyQT4 不規則圖形界面

弄了一下午的qt,到現在總算出來效果了,下面的代碼,添加了個滑動條,拖拽可以實現窗體透明效果,button自然就更不在話下了,由於對qt不熟悉(答案基本是doc + google出來的),所以細節不好說,呵呵,事件是connect加上的,而要加控制項,需要加一個布局吧。
from PyQt4 import QtCore, QtGui
from PyQt4.QtGui import *
from PyQt4.QtCore import *

class MyForm(QWidget):
def __init__(self, parent=None):
super(MyForm,self).__init__(parent)

self.pix = QPixmap("mac.png")
self.resize(self.pix.size())
self.setMask(self.pix.mask())

slider = QSlider(Qt.Horizontal, self)
slider.valueChanged.connect(self.setAlpha)
layout = QVBoxLayout()
layout.addWidget(slider)
self.setLayout(layout)

def setAlpha(self, value):
self.setWindowOpacity((100 - value)/100)

def paintEvent(self,event):
painter = QPainter(self)
painter.drawPixmap(0,0,self.pix.width(),self.pix.height(),self.pix)

app = QApplication([])
form = MyForm()
form.show()
app.exec_()

㈢ 如何用python對整個文章截圖

方法一、使用PyQt4的QtWebKit組件

#!/usr/bin/envpython
#-*-coding:UTF-8-*-
#來源http://www.oschina.net/code/snippet_219811_14920

importsys
importos.path
fromPyQt4importQtGui,QtCore,QtWebKit

classPageShotter(QtGui.QWidget):
def__init__(self,url,filename,parent=None):
QtGui.QWidget.__init__(self,parent)
self.url=url
self.filename=filename
self.webpage=None

defshot(self):
webview=QtWebKit.QWebView(self)
webview.load(QtCore.QUrl(self.url))
self.webpage=webview.page()
self.connect(webview,QtCore.SIGNAL("loadFinished(bool)"),self.save_page)

defsave_page(self,finished):
#printfinished
iffinished:
printu"開始截圖!"
size=self.webpage.mainFrame().contentsSize()
printu"頁面寬:%d,頁面高:%d"%(size.width(),size.height())
self.webpage.setViewportSize(QtCore.QSize(size.width()+16,size.height()))
img=QtGui.QImage(size,QtGui.QImage.Format_ARGB32)
painter=QtGui.QPainter(img)
self.webpage.mainFrame().render(painter)
painter.end()
filename=self.filename;
ifimg.save(filename):
filepath=os.path.join(os.path.dirname(__file__),filename)
printu"截圖完畢:%s"%filepath
else:
printu"截圖失敗";
else:
printu"網頁載入失敗!"
self.close()

if__name__=="__main__":
app=QtGui.QApplication(sys.argv)
#shotter=PageShotter("http://www.adssfwewfdsfdsf.com")
shotter=PageShotter("http://www.youku.com/",'shot.png')
shotter.shot()
sys.exit(app.exec_())


方法二、使用selenium


#!/usr/bin/envpython
#-*-coding:UTF-8-*-

importtime
fromseleniumimportwebdriver

browser=webdriver.Firefox()
browser.set_window_size(1055,800)
browser.get("http://www.yooli.com/")
browser.find_element_by_id("idClose").click()
time.sleep(5)

browser.save_screenshot("shot.png")
browser.quit()

linux下通過php無法調用QT程序 求助,我在linux下調用qt程序失敗,在console下能正常運行。

GTK和QT在手機和嵌入式設備上應用都很廣泛。如Nokia的手機主要用QT。如intel我知道python應該可以做到,QT,GTK簡單的還成,要是去調用,都不太好辦。

㈤ python下,如何在Qlabel顯示的圖片上繪圖

㈥ python 做一個仿windows的記事本,頁面設置功能該怎麼實現網上找了半天沒有合適的代碼

Python本身是沒有圖形界面處理能力的,它還是得依靠第三方模塊,比如PyQt5就有三種方式可以實現你的需求:

  1. 使用HTML和QTextDOcument列印文檔

  2. 使用QTextCusor和QTextDocument列印文檔

  3. 使用QPainter列印文檔

具體怎麼實現需要你自己查閱開發文檔,我不提供便利給伸手黨。

㈦ python pyqt怎麼畫圓

這個例子我做了好幾天:

1)官網C++的源碼,改寫成PyQt5版本的代碼,好多細節不會轉化

2)網上的PyQt的例子根本運行不了

填了無數個坑,結合二者,終於能完成了一個關於繪圖的東西。這個過程也掌握了很多新的知識點

【知識點】

1、關於多個點的使用

poitns = [QPoint(10, 80), QPoint(20, 10), QPoint(80, 30), QPoint(90, 70)]

請看:

import sysfrom PyQt5.QtCore import *from PyQt5.QtGui import *from PyQt5.QtWidgets import *class StockDialog(QWidget): def __init__(self, parent=None):
super(StockDialog, self).__init__(parent)
self.setWindowTitle("利用QPainter繪制各種圖形")

mainSplitter = QSplitter(Qt.Horizontal)
mainSplitter.setOpaqueResize(True)

frame = QFrame(mainSplitter)
mainLayout = QGridLayout(frame) #mainLayout.setMargin(10)
mainLayout.setSpacing(6)

label1=QLabel("形狀:")
label2=QLabel("畫筆線寬:")
label3=QLabel("畫筆顏色:")
label4=QLabel("畫筆風格:")
label5=QLabel("畫筆頂端:")
label6=QLabel("畫筆連接點:")
label7=QLabel("畫刷風格:")
label8=QLabel("畫刷顏色:")

self.shapeComboBox = QComboBox()
self.shapeComboBox.addItem("Line", "Line")
self.shapeComboBox.addItem("Rectangle", "Rectangle")
self.shapeComboBox.addItem('Rounded Rectangle','Rounded Rectangle')
self.shapeComboBox.addItem('Ellipse','Ellipse')
self.shapeComboBox.addItem('Pie','Pie')
self.shapeComboBox.addItem('Chord','Chord')
self.shapeComboBox.addItem('Path','Path')
self.shapeComboBox.addItem('Polygon','Polygon')
self.shapeComboBox.addItem('Polyline','Polyline')
self.shapeComboBox.addItem('Arc','Arc')
self.shapeComboBox.addItem('Points','Points')
self.shapeComboBox.addItem('Text','Text')
self.shapeComboBox.addItem('Pixmap','Pixmap')

self.widthSpinBox = QSpinBox()
self.widthSpinBox.setRange(0,20)

self.penColorFrame = QFrame()
self.penColorFrame.setAutoFillBackground(True)
self.penColorFrame.setPalette(QPalette(Qt.blue))
self.penColorPushButton = QPushButton("更改")

self.penStyleComboBox = QComboBox()
self.penStyleComboBox.addItem("Solid",Qt.SolidLine)
self.penStyleComboBox.addItem('Dash', Qt.DashLine)
self.penStyleComboBox.addItem('Dot', Qt.DotLine)
self.penStyleComboBox.addItem('Dash Dot', Qt.DashDotLine)
self.penStyleComboBox.addItem('Dash Dot Dot', Qt.DashDotDotLine)
self.penStyleComboBox.addItem('None', Qt.NoPen)

self.penCapComboBox = QComboBox()
self.penCapComboBox.addItem("Flat",Qt.FlatCap)
self.penCapComboBox.addItem('Square', Qt.SquareCap)
self.penCapComboBox.addItem('Round', Qt.RoundCap)

self.penJoinComboBox = QComboBox()
self.penJoinComboBox.addItem("Miter",Qt.MiterJoin)
self.penJoinComboBox.addItem('Bebel', Qt.BevelJoin)
self.penJoinComboBox.addItem('Round', Qt.RoundJoin)

self.brushStyleComboBox = QComboBox()
self.brushStyleComboBox.addItem("Linear Gradient",Qt.LinearGradientPattern)
self.brushStyleComboBox.addItem('Radial Gradient', Qt.RadialGradientPattern)
self.brushStyleComboBox.addItem('Conical Gradient', Qt.ConicalGradientPattern)
self.brushStyleComboBox.addItem('Texture', Qt.TexturePattern)
self.brushStyleComboBox.addItem('Solid', Qt.SolidPattern)
self.brushStyleComboBox.addItem('Horizontal', Qt.HorPattern)
self.brushStyleComboBox.addItem('Vertical', Qt.VerPattern)
self.brushStyleComboBox.addItem('Cross', Qt.CrossPattern)
self.brushStyleComboBox.addItem('Backward Diagonal', Qt.BDiagPattern)
self.brushStyleComboBox.addItem('Forward Diagonal', Qt.FDiagPattern)
self.brushStyleComboBox.addItem('Diagonal Cross', Qt.DiagCrossPattern)
self.brushStyleComboBox.addItem('Dense 1', Qt.Dense1Pattern)
self.brushStyleComboBox.addItem('Dense 2', Qt.Dense2Pattern)
self.brushStyleComboBox.addItem('Dense 3', Qt.Dense3Pattern)
self.brushStyleComboBox.addItem('Dense 4', Qt.Dense4Pattern)
self.brushStyleComboBox.addItem('Dense 5', Qt.Dense5Pattern)
self.brushStyleComboBox.addItem('Dense 6', Qt.Dense6Pattern)
self.brushStyleComboBox.addItem('Dense 7', Qt.Dense7Pattern)
self.brushStyleComboBox.addItem('None', Qt.NoBrush)

self.brushColorFrame = QFrame()
self.brushColorFrame.setAutoFillBackground(True)
self.brushColorFrame.setPalette(QPalette(Qt.green))
self.brushColorPushButton = QPushButton("更改")

labelCol=0
contentCol=1
#建立布局
mainLayout.addWidget(label1,1,labelCol)
mainLayout.addWidget(self.shapeComboBox,1,contentCol)
mainLayout.addWidget(label2,2,labelCol)
mainLayout.addWidget(self.widthSpinBox,2,contentCol)
mainLayout.addWidget(label3,4,labelCol)
mainLayout.addWidget(self.penColorFrame,4,contentCol)
mainLayout.addWidget(self.penColorPushButton,4,3)
mainLayout.addWidget(label4,6,labelCol)
mainLayout.addWidget(self.penStyleComboBox,6,contentCol)
mainLayout.addWidget(label5,8,labelCol)
mainLayout.addWidget(self.penCapComboBox,8,contentCol)
mainLayout.addWidget(label6,10,labelCol)
mainLayout.addWidget(self.penJoinComboBox,10,contentCol)
mainLayout.addWidget(label7,12,labelCol)
mainLayout.addWidget(self.brushStyleComboBox,12,contentCol)
mainLayout.addWidget(label8,14,labelCol)
mainLayout.addWidget(self.brushColorFrame,14,contentCol)
mainLayout.addWidget(self.brushColorPushButton,14,3)
mainSplitter1 = QSplitter(Qt.Horizontal)
mainSplitter1.setOpaqueResize(True)

stack1 = QStackedWidget()
stack1.setFrameStyle(QFrame.Panel|QFrame.Raised)
self.area = PaintArea()
stack1.addWidget(self.area)
frame1 = QFrame(mainSplitter1)
mainLayout1 = QVBoxLayout(frame1) #mainLayout1.setMargin(10)
mainLayout1.setSpacing(6)
mainLayout1.addWidget(stack1)

layout = QGridLayout(self)
layout.addWidget(mainSplitter1,0,0)
layout.addWidget(mainSplitter,0,1)
self.setLayout(layout)
#信號和槽函數 self.shapeComboBox.activated.connect(self.slotShape)
self.widthSpinBox.valueChanged.connect(self.slotPenWidth)
self.penColorPushButton.clicked.connect(self.slotPenColor)
self.penStyleComboBox.activated.connect(self.slotPenStyle)
self.penCapComboBox.activated.connect(self.slotPenCap)
self.penJoinComboBox.activated.connect(self.slotPenJoin)
self.brushStyleComboBox.activated.connect(self.slotBrush)
self.brushColorPushButton.clicked.connect(self.slotBrushColor)

self.slotShape(self.shapeComboBox.currentIndex())
self.slotPenWidth(self.widthSpinBox.value())
self.slotBrush(self.brushStyleComboBox.currentIndex())

def slotShape(self,value):
shape = self.area.Shape[value]
self.area.setShape(shape)
def slotPenWidth(self,value):
color = self.penColorFrame.palette().color(QPalette.Window)
style = Qt.PenStyle(self.penStyleComboBox.itemData(self.penStyleComboBox.currentIndex(),Qt.UserRole))
cap = Qt.PenCapStyle(self.penCapComboBox.itemData(self.penCapComboBox.currentIndex(),Qt.UserRole))
join = Qt.PenJoinStyle(self.penJoinComboBox.itemData(self.penJoinComboBox.currentIndex(),Qt.UserRole))
self.area.setPen(QPen(color,value,style,cap,join))
def slotPenStyle(self,value):
self.slotPenWidth(value)
def slotPenCap(self,value):
self.slotPenWidth(value)
def slotPenJoin(self,value):
self.slotPenWidth(value)
def slotPenColor(self):
color = QColorDialog.getColor(Qt.blue)
self.penColorFrame.setPalette(QPalette(color))
self.area.setPen(QPen(color))
def slotBrushColor(self):
color = QColorDialog.getColor(Qt.blue)
self.brushColorFrame.setPalette(QPalette(color))
self.slotBrush(self.brushStyleComboBox.currentIndex())
def slotBrush(self,value):
color = self.brushColorFrame.palette().color(QPalette.Window)
style = Qt.BrushStyle(self.brushStyleComboBox.itemData(value,Qt.UserRole))
if(style == Qt.Lin

㈧ python可以製作時鍾嗎

調試調試,參考參考

import sys
from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import Qt
from PyQt4.QtCore import QPoint
from PyQt4.QtCore import QTimer
from PyQt4.QtCore import QTime
from PyQt4.QtGui import QPainter
from PyQt4.QtGui import QColor
from PyQt4.QtGui import QPolygon
from PyQt4.QtCore import SIGNAL as signal

class Clock(QtGui.QWidget):
'''
classdocs
'''

def __init__(self):
'''
Constructor
'''
super(Clock, self).__init__()
self.hourColor=QColor(127, 0, 127);
self.minuteColor=QColor(0, 127, 127, 191)
self.secondColor=QColor(127, 127,0,120)
self.initUI()
self.timer = QTimer()
self.timer.timeout.connect(self.update)
self.timer.start(30)
self.show()

def handChange(self):

self.side = min(self.width(), self.height())
self.hand=(max(self.side/200,4), max(self.side/100,8), max(self.side/40,30))
self.hourHand=QPolygon([QPoint(self.hand[0],self.hand[1]),QPoint(-self.hand[0],self.hand[1]),QPoint(0,-self.hand[2])])
self.minuteHand=QPolygon([QPoint(self.hand[0],self.hand[1]),QPoint(-self.hand[0],self.hand[1]),QPoint(0,-self.hand[2]*2)])
self.secondHand=QPolygon([QPoint(self.hand[0],self.hand[1]),QPoint(-self.hand[0],self.hand[1]),QPoint(0,-self.hand[2]*3)])

def set_transparency(self, enabled):
if enabled:
self.setAutoFillBackground(False)
else:
self.setAttribute(Qt.WA_NoSystemBackground, False)
#下面這種方式好像不行
# pal=QtGui.QPalette()
# pal.setColor(QtGui.QPalette.Background, QColor(127, 127,10,120))
# self.setPalette(pal)
self.setAttribute(Qt.WA_TranslucentBackground, enabled)
self.repaint()

def initUI(self):

self.setGeometry(300, 300, 300, 200)
self.setWindowTitle('Clock')
self.handChange()
self.rightButton=False
# 下面兩個配合實現窗體透明和置頂
sizeGrip=QtGui.QSizeGrip(self)
self.setWindowFlags(Qt.FramelessWindowHint|Qt.WindowStaysOnTopHint|Qt.SubWindow )
#self.setMouseTracking(True);
self.trans=True

self.set_transparency(True)

quitAction = QtGui.QAction(QtGui.QIcon('quit.png'), '&Quit', self)
self.connect(quitAction,signal("triggered()"),QtGui.qApp.quit)
backAction = QtGui.QAction( '&Back', self)
self.connect(backAction,signal("triggered()"),self.backClicked)
self.popMenu= QtGui.QMenu()
self.popMenu.addAction(quitAction)
self.popMenu.addAction(backAction)

def resizeEvent(self, e):
self.handChange()

def backClicked(self):
if self.trans == True :
self.trans = False
self.set_transparency(False)
else:
self.trans = True
self.set_transparency(True)

def mouseReleaseEvent(self,e):
if self.rightButton == True:
self.rightButton=False
self.popMenu.popup(e.globalPos())

def mouseMoveEvent(self, e):
if e.buttons() & Qt.LeftButton:
self.move(e.globalPos()-self.dragPos)
e.accept()
def mousePressEvent(self, e):

if e.button() == Qt.LeftButton:
self.dragPos=e.globalPos()-self.frameGeometry().topLeft()
e.accept()
if e.button() == Qt.RightButton and self.rightButton == False:
self.rightButton=True

def paintEvent(self, e):
time = QTime.currentTime()
qp = QPainter()

qp.begin(self)
qp.setRenderHint(QPainter.Antialiasing) # 開啟這個抗鋸齒,會很佔cpu的!
qp.translate(self.width() / 2, self.height() / 2)
qp.scale(self.side / 200.0, self.side / 200.0)

qp.setPen(QtCore.Qt.NoPen)
qp.setBrush(self.hourColor)
qp.save()
qp.rotate(30.0 * ((time.hour() + time.minute()/ 60.0)))
qp.drawConvexPolygon(self.hourHand)
qp.restore()

qp.setPen(self.hourColor)
for i in range(12):
qp.drawLine(88, 0, 96, 0)
qp.rotate(30.0)

qp.setPen(QtCore.Qt.NoPen)
qp.setBrush(self.minuteColor)
qp.save()

qp.rotate(6.0 * ((time.minute() + (time.second()+time.msec()/1000.0) / 60.0)))
qp.drawConvexPolygon(self.minuteHand)
qp.restore()

qp.setPen(self.minuteColor)
for i in range(60):
if (i % 5) is not 0:
qp.drawLine(92, 0, 96, 0)
qp.rotate(6.0)

qp.setPen(QtCore.Qt.NoPen)
qp.setBrush(self.secondColor)
qp.save()
qp.rotate(6.0*(time.second()+time.msec()/1000.0))
qp.drawConvexPolygon(self.secondHand)
qp.restore()
qp.end()
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
clock = Clock()
sys.exit(app.exec_())

閱讀全文

與pythonqpainter相關的資料

熱點內容
文件名修改為文件夾的名字批處理 瀏覽:251
拍照程序員 瀏覽:827
wps怎麼把pdf轉jpg 瀏覽:217
自拍用什麼app做的藝術照 瀏覽:169
h3c無線配置命令 瀏覽:515
linux代碼閱讀工具 瀏覽:160
能夠畫出對稱圖形的是什麼app 瀏覽:424
單片機投票器 瀏覽:467
程序員那麼可愛唱嗎 瀏覽:830
手機誤刪的app怎麼恢復 瀏覽:700
java第三方加密庫 瀏覽:660
編譯代碼軟體哪個好 瀏覽:997
編譯器軟體圖片 瀏覽:880
美團專送app怎麼不接受遠單 瀏覽:833
伺服器mgmt口如何連接電腦 瀏覽:798
做程序員至少要精通幾種 瀏覽:673
個人用雲伺服器價格對比 瀏覽:257
如何遠程刪除伺服器文件夾 瀏覽:779
a9賬號如何移植到安卓 瀏覽:340
gpib介面編程 瀏覽:468