def paintEvent(self, event):
self._draw_graph()
self._draw_reticle()
painter = QtGui.QPainter(self)
try:
painter.setRenderHint(QtGui.QPainter.Antialiasing)
painter.setPen(QtGui.QPen())
painter.setBrush(QtGui.QBrush())
if self._graph:
painter.drawPixmap(0, 0, self._graph)
if self._path_max:
painter.setPen(Qt.green)
painter.drawPath(self._path_max)
painter.setOpacity(0.5)
if self._reticle:
painter.drawPixmap(0, 0, self._reticle)
finally:
painter.end()
python类QBrush()的实例源码
def __init__(self, item, timeline_range, *args, **kwargs):
super(_BaseItem, self).__init__(*args, **kwargs)
self.item = item
self.timeline_range = timeline_range
self.setFlags(QtGui.QGraphicsItem.ItemIsSelectable)
self.setBrush(
QtGui.QBrush(QtGui.QColor(180, 180, 180, 255))
)
self.source_in_label = QtGui.QGraphicsSimpleTextItem(self)
self.source_out_label = QtGui.QGraphicsSimpleTextItem(self)
self.source_name_label = QtGui.QGraphicsSimpleTextItem(self)
self._add_markers()
self._set_labels()
def paint(self, painter, option, index):
painter.save()
painter.setPen(QtGui.QPen(QtCore.Qt.NoPen))
if option.state & QtGui.QStyle.State_Selected:
painter.setBrush(QtGui.QBrush(
self.parent().palette().highlight().color()))
else:
painter.setBrush(QtGui.QBrush(QtCore.Qt.white))
painter.drawRect(option.rect)
painter.setPen(QtGui.QPen(QtCore.Qt.black))
painter.drawText(option.rect, QtCore.Qt.AlignLeft|QtCore.Qt.AlignCenter,
index.data())
painter.restore()
def paintEvent(self, event):
painter = QPainter()
painter.begin(self)
painter.setRenderHint(QPainter.Antialiasing)
painter.fillRect(event.rect(), QBrush(QColor(127, 127, 127, 127)))
painter.setPen(QPen(Qt.NoPen))
for i in range(6):
if int(self.counter / 10) % 6 == i:
factor = self.counter % 10
if factor >= 5:
factor = 5 - (self.counter % 5)
painter.setBrush(QBrush(QColor(95 + factor * 32, 127, 127)))
else:
painter.setBrush(QBrush(QColor(127, 127, 127)))
painter.drawEllipse(
self.width() / 2 + 30 * math.cos(2 * math.pi * i / 6.0) - 10,
self.height() / 2 + 30 * math.sin(2 * math.pi * i / 6.0) - 10,
20, 20)
painter.end()
def paintEvent(self, event):
self._draw_graph()
self._draw_reticle()
painter = QtGui.QPainter(self)
try:
painter.setRenderHint(QtGui.QPainter.Antialiasing)
painter.setPen(QtGui.QPen())
painter.setBrush(QtGui.QBrush())
if self._graph:
painter.drawPixmap(0, 0, self._graph)
if self._path_max:
painter.setPen(Qt.green)
painter.drawPath(self._path_max)
painter.setOpacity(0.5)
if self._reticle:
painter.drawPixmap(0, 0, self._reticle)
finally:
painter.end()
def paintEvent(self, event):
self._draw_graph()
self._draw_reticle()
painter = QtGui.QPainter(self)
try:
painter.setRenderHint(QtGui.QPainter.Antialiasing)
painter.setPen(QtGui.QPen())
painter.setBrush(QtGui.QBrush())
if self._graph:
painter.drawPixmap(0, 0, self._graph)
if self._path_max:
painter.setPen(Qt.green)
painter.drawPath(self._path_max)
painter.setOpacity(0.5)
if self._reticle:
painter.drawPixmap(0, 0, self._reticle)
finally:
painter.end()
def paintEvent(self, event):
self._draw_graph()
self._draw_reticle()
painter = QtGui.QPainter(self)
try:
painter.setRenderHint(QtGui.QPainter.Antialiasing)
painter.setPen(QtGui.QPen())
painter.setBrush(QtGui.QBrush())
if self._graph:
painter.drawPixmap(0, 0, self._graph)
if self._path_max:
painter.setPen(Qt.green)
painter.drawPath(self._path_max)
painter.setOpacity(0.5)
if self._reticle:
painter.drawPixmap(0, 0, self._reticle)
finally:
painter.end()
def paintEvent(self, event):
'''Paint the button grey if not highlighted, else yellow'''
painter = QtGui.QPainter(self)
colour = QtGui.QColor(247, 147, 30, 150)
gradient = QtGui.QLinearGradient(QtCore.QPoint(0,0), QtCore.QPoint(self.width()/2, 0))
gradient.setColorAt(0, QtCore.Qt.transparent)
gradient.setColorAt(1, colour)
gradient.setSpread(QtGui.QGradient.ReflectSpread)
painter.setBrush(QtGui.QBrush(gradient))
painter.setPen(QtCore.Qt.transparent)
rect = QtCore.QRect(0,0,self.width(),self.height())
painter.drawRect(rect)
def __init__(self, *args, **kwargs):
super(GapItem, self).__init__(*args, **kwargs)
self.setBrush(
QtGui.QBrush(QtGui.QColor(100, 100, 100, 255))
)
self.source_name_label.setText('GAP')
def __init__(self, item, timeline_range, rect, *args, **kwargs):
rect.setHeight(TRANSITION_HEIGHT)
super(TransitionItem, self).__init__(
item,
timeline_range,
rect,
*args,
**kwargs
)
self.setBrush(
QtGui.QBrush(QtGui.QColor(237, 228, 148, 255))
)
self.setY(TRACK_HEIGHT - TRANSITION_HEIGHT)
self.setZValue(2)
# add extra bit of shading
shading_poly_f = QtGui.QPolygonF()
shading_poly_f.append(QtCore.QPointF(0, 0))
shading_poly_f.append(QtCore.QPointF(rect.width(), 0))
shading_poly_f.append(QtCore.QPointF(0, rect.height()))
shading_poly = QtGui.QGraphicsPolygonItem(shading_poly_f, parent=self)
shading_poly.setBrush(QtGui.QBrush(QtGui.QColor(0, 0, 0, 30)))
try:
shading_poly.setPen(QtCore.Qt.NoPen)
except TypeError:
shading_poly.setPen(QtCore.Qt.transparent)
def __init__(self, *args, **kwargs):
super(ClipItem, self).__init__(*args, **kwargs)
self.setBrush(QtGui.QBrush(QtGui.QColor(168, 197, 255, 255)))
self.source_name_label.setText(self.item.name)
def __init__(self, *args, **kwargs):
super(NestedItem, self).__init__(*args, **kwargs)
self.setBrush(
QtGui.QBrush(QtGui.QColor(255, 113, 91, 255))
)
self.source_name_label.setText(self.item.name)
def __init__(self, marker, *args, **kwargs):
self.item = marker
poly = QtGui.QPolygonF()
poly.append(QtCore.QPointF(0.5 * MARKER_SIZE, -0.5 * MARKER_SIZE))
poly.append(QtCore.QPointF(0.5 * MARKER_SIZE, 0.5 * MARKER_SIZE))
poly.append(QtCore.QPointF(0, MARKER_SIZE))
poly.append(QtCore.QPointF(-0.5 * MARKER_SIZE, 0.5 * MARKER_SIZE))
poly.append(QtCore.QPointF(-0.5 * MARKER_SIZE, -0.5 * MARKER_SIZE))
super(Marker, self).__init__(poly, *args, **kwargs)
self.setFlags(QtGui.QGraphicsItem.ItemIsSelectable)
self.setBrush(QtGui.QBrush(QtGui.QColor(121, 212, 177, 255)))
def __init__(self, *args, **kwargs):
super(TimeSlider, self).__init__(*args, **kwargs)
self.setBrush(QtGui.QBrush(QtGui.QColor(64, 78, 87, 255)))
def __init__(self, composition, *args, **kwargs):
super(CompositionWidget, self).__init__(*args, **kwargs)
self.composition = composition
self.setBackgroundBrush(QtGui.QBrush(QtGui.QColor(64, 78, 87, 255)))
self._adjust_scene_size()
self._add_time_slider()
self._add_tracks()
self._add_markers()
def modelsListsetRowColor(self, item, color):
item.setBackground(0, QtGui.QBrush(QtGui.QColor(color[0], color[1], color[2])))
item.setBackground(1, QtGui.QBrush(QtGui.QColor(color[0], color[1], color[2])))
item.setBackground(2, QtGui.QBrush(QtGui.QColor(color[0], color[1], color[2])))
item.setBackground(3, QtGui.QBrush(QtGui.QColor(color[0], color[1], color[2])))
#item.setBackground(4, QtGui.QBrush(QtGui.QColor(color[0], color[1], color[2])))
def checkPath(self, item):
[boolValue, path] = partExistPath(item.text())
if boolValue:
item.setForeground(QtGui.QBrush(QtGui.QColor(72, 144, 0)))
item.setData(QtCore.Qt.UserRole, path)
if item.checkState() != QtCore.Qt.Checked:
item.setCheckState(QtCore.Qt.Unchecked)
else:
item.setForeground(QtGui.QBrush(QtGui.QColor(255, 0, 0)))
item.setCheckState(QtCore.Qt.Checked)
item.setData(QtCore.Qt.UserRole, '')
def paint(self, painter, option, index):
if index.column() > 2:
super(SpectralModelsTableDelegate, self).paint(painter, option, index)
return None
painter.save()
# set background color
painter.setPen(QtGui.QPen(QtCore.Qt.NoPen))
if option.state & QtGui.QStyle.State_Selected:
painter.setBrush(QtGui.QBrush(
self.parent().palette().highlight().color()))
else:
# Does this row have a conflict?
conflicts = self.session._spectral_model_conflicts
conflict_indices = np.hstack([sum([], conflicts)])
row = index.row()
if row in conflict_indices:
for i, conflict in enumerate(conflicts):
if row in conflict:
color = _COLORS[i % len(_COLORS)]
break
painter.setBrush(QtGui.QBrush(QtGui.QColor(color)))
else:
painter.setBrush(QtGui.QBrush(QtCore.Qt.white))
painter.drawRect(option.rect)
# set text color
painter.setPen(QtGui.QPen(QtCore.Qt.black))
painter.drawText(option.rect, QtCore.Qt.AlignLeft|QtCore.Qt.AlignCenter, index.data())
painter.restore()
def paintEvent(self, event=None):
painter = QtGui.QPainter(self)
if self.color is not None:
painter.setBrush(QtGui.QBrush(self.color))
rect = self.rect()
margins = self.contentsMargins()
new_rect = QtCore.QRect(rect.left()+margins.left(),
rect.top()+margins.top(),
rect.width()-margins.right()*2,
rect.height()-margins.bottom()*2)
painter.drawRect(new_rect)
def paint(self,painter,option, widget):
pen = QtGui.QPen()
pen.setWidth(1)
brush = QtGui.QBrush()
brush.setStyle(QtCore.Qt.SolidPattern)
brush.setColor(QtGui.QColor("white"))
painter.setBrush(brush)
painter.drawRect(self.rect)
def __init__(self):
super(NodeView,self).__init__()
self._scene = OPScene()
# Obsolete
self.nodeList = list()
# Variables
self.clickedItem = None
self.itemMode = None # Define which item is selected
self.mousePositionX = 0
self.mousePositionY = 0
self.mode = None
# Configure QGraphics View
self.setSceneRect(0, 0, -1, -1)
self.setFocusPolicy(QtCore.Qt.ClickFocus)
self.setMouseTracking(True)
self.setRenderHints(QtGui.QPainter.Antialiasing)
self.setViewportUpdateMode(QtGui.QGraphicsView.FullViewportUpdate)
# Init QGraphic Scene
self.sc = QtGui.QGraphicsScene()
self.setScene(self.sc)
self.sceneScale = 0.7
# Paint the background
brush = QtGui.QBrush()
brush.setTransform(QtGui.QTransform().scale(0.75, 0.75))
brush.setTextureImage(QtGui.QImage("/Users/draknova/Documents/workspace/sPipe/bin/images/gridTexture.jpg"))
self.sc.setBackgroundBrush(brush)
######################
####### EVENTS #######
######################
### KEYBOARD EVENTS ##
def _add_table_row(self,items):
new_row = self._table.rowCount()+1
self._table.setRowCount(new_row)
for i, item in enumerate(items):
if type(item) != bool:
if i == 4:
self.new_item = QtGui.QPushButton('Backup!')
self.new_item.clicked.connect(self.handle_manual_backup)
self._table.setCellWidget(new_row-1,i,self.new_item)
continue
elif i == 5 and item != None:
if item != '...':
new_item = QtGui.QTableWidgetItem('{}'.format(item))
link_font = QtGui.QFont(new_item.font())
link_font.setUnderline(True)
new_item.setFont(link_font)
new_item.setTextAlignment(QtCore.Qt.AlignCenter)
new_item.setForeground(QtGui.QBrush(QtGui.QColor("teal")))
else:
new_item = QtGui.QTableWidgetItem('{}'.format(item))
new_item.setTextAlignment(QtCore.Qt.AlignCenter)
elif i == 1 and item == None:
new_item = QtGui.QTableWidgetItem('no backups')
new_item.setForeground(QtGui.QBrush(QtGui.QColor("grey")))
else:
new_item = QtGui.QTableWidgetItem(item)
new_item.setFlags(QtCore.Qt.ItemIsEnabled)
elif type(item) == bool:
new_item = QtGui.QTableWidgetItem()
if i == 3 and items[2] == False:
new_item.setFlags(QtCore.Qt.ItemFlags() != QtCore.Qt.ItemIsEnabled)
new_item.setCheckState(QtCore.Qt.Unchecked)
else:
new_item.setFlags(QtCore.Qt.ItemIsUserCheckable|QtCore.Qt.ItemIsEnabled)
new_item.setCheckState(QtCore.Qt.Unchecked if item == False else QtCore.Qt.Checked)
self._table.setItem(new_row-1,i,new_item)
def data(self,index,role = QtCore.Qt.DisplayRole):
try:
if role == QtCore.Qt.BackgroundColorRole and index.isValid():
for item in self.__colorRow.values():
if index.row() in item["indexes"]:
#return item["color"]
return QtGui.QBrush(QtCore.Qt.yellow)
except:
pass
return super(QtGui.QSortFilterProxyModel,self).data(index,role)
def paintEvent(self, event):
'''Paint the button grey if not highlighted, else yellow'''
painter = QtGui.QPainter(self)
colour = QtGui.QColor(247, 147, 30, 150)
gradient = QtGui.QLinearGradient(QtCore.QPoint(0,0), QtCore.QPoint(self.width()/2, 0))
gradient.setColorAt(0, QtCore.Qt.transparent)
gradient.setColorAt(1, colour)
gradient.setSpread(QtGui.QGradient.ReflectSpread)
painter.setBrush(QtGui.QBrush(gradient))
painter.setPen(QtCore.Qt.transparent)
rect = QtCore.QRect(0,0,self.width(),self.height())
painter.drawRect(rect)
def fill_project_table(self, table):
#copy = db.studio() # self.db_studio
self.db_group.get_list_projects()
if not self.db_group.list_projects:
return
projects = []
for key in self.db_group.list_projects.keys():
projects.append({'name' : key,'status' : self.db_group.list_projects[key]['status'], 'path': self.db_group.list_projects[key]['path']})
# get table data
columns = ('name', 'status', 'path')
num_row = len(projects)
num_column = len(columns)
headers = columns
# make table
table.setColumnCount(num_column)
table.setRowCount(num_row)
table.setHorizontalHeaderLabels(headers)
# fill table
for i, project in enumerate(projects):
for j,key in enumerate(headers):
newItem = QtGui.QTableWidgetItem()
newItem.setText(project[key])
if key == 'name':
color = self.project_color
brush = QtGui.QBrush(color)
newItem.setBackground(brush)
table.setItem(i, j, newItem)
table.resizeRowsToContents()
table.resizeColumnsToContents()
print('fill project table')
def tm_edit_readers_ui_reload_table(self):
table = self.editReadersDialog.select_from_list_data_list_table
# load table
headers = ['nik_name']
num_column = len(headers)
num_row = 0
if self.cleaned_readers_list:
num_row = len(self.cleaned_readers_list)
table.setColumnCount(num_column)
table.setRowCount(num_row)
table.setHorizontalHeaderLabels(headers)
if self.cleaned_readers_list:
for i,reader_name in enumerate(self.cleaned_readers_list):
if reader_name == 'first_reader':
continue
for j,key in enumerate(headers):
newItem = QtGui.QTableWidgetItem()
if key == 'nik_name':
newItem.setText(reader_name)
if 'first_reader' in self.current_readers_list:
if self.current_readers_list['first_reader'] == reader_name:
newItem.setText((reader_name + ' (***)'))
color = self.artist_color
brush = QtGui.QBrush(color)
newItem.setBackground(brush)
newItem.reader_name = reader_name
table.setItem(i, j, newItem)
def tm_add_readers_ui_load_artist_list(self, workrom_name):
table = self.selectReadersDialog.select_from_list_data_list_table
workroom_dict = self.selectReadersDialog.workroom_dict
self.clear_table(table)
result = self.db_workroom.read_artist_of_workroom(workroom_dict[workrom_name]['id'])
if not result[0]:
self.message(result[1], 2)
artirs_dict = result[1]
# load table
headers = ['nik_name', 'level']
num_column = len(headers)
num_row = 0
if artirs_dict:
num_row = len(artirs_dict)
table.setColumnCount(num_column)
table.setRowCount(num_row)
table.setHorizontalHeaderLabels(headers)
if artirs_dict:
for i,reader_name in enumerate(artirs_dict):
for j,key in enumerate(headers):
newItem = QtGui.QTableWidgetItem()
newItem.setText(artirs_dict[reader_name][key])
newItem.reader_name = reader_name
if key == 'nik_name':
color = self.artist_color
brush = QtGui.QBrush(color)
newItem.setBackground(brush)
if self.current_readers_list:
if reader_name in self.current_readers_list.keys():
color = self.grey_color
brush = QtGui.QBrush(color)
newItem.setBackground(brush)
table.setItem(i, j, newItem)
def tm_change_task_artist_action(self, window, item_):
# get new artist
new_artist = window.combo_dialog_combo_box.currentText()
if new_artist in ['None', '-None-']:
new_artist = ''
# change artist
task_data = dict(item_.task)
result = self.db_chat.change_artist(self.current_project, task_data, new_artist)
if not result[0]:
self.message(result[1], 2)
return
new_status = result[1][0]
outsource = result[1][1]
#print(new_status)
# edit labels
self.myWidget.tm_data_label_1.setText(new_artist)
task_data['artist'] = new_artist
if new_status:
task_data['status'] = new_status
task_data['outsource'] = outsource
item_.task = task_data
# change table color
rgb = self.db_chat.color_status[task_data['status']]
r = (rgb[0]*255)
g = (rgb[1]*255)
b = (rgb[2]*255)
color = QtGui.QColor(r, g, b)
brush = QtGui.QBrush(color)
item_.setBackground(brush)
self.close_window(window)
# ------ change input --------------
def paintEvent(self, event):
painter = QPainter()
painter.begin(self)
colour = self._colour
if not self._lit:
colour = self._colour.darker(300)
painter.setPen(QPen(Qt.black, 1))
painter.setBrush(QBrush(colour))
rect = event.rect()
radius = min(rect.width(), rect.height()) / 3
painter.drawEllipse(rect.center(), radius, radius)
painter.end()
def paint(self,painter,option, widget):
blackPen = QtGui.QPen()
whitePen = QtGui.QPen()
blackPen.setWidth(1)
whitePen.setWidth(1)
blackPen.setColor(QtGui.QColor("black"))
whitePen.setColor(QtGui.QColor("white"))
if self.isSelected():
gradient = QtGui.QLinearGradient(QtCore.QPointF(0, 0), QtCore.QPointF(0, 20))
gradient.setColorAt(0, QtGui.QColor(220,170,50))
gradient.setColorAt(0.3, QtGui.QColor(220,170,50))
gradient.setColorAt(1, QtGui.QColor(170,150,40))
#brush = QtGui.QBrush(gradient)
#brush.setStyle(QtCore.Qt.LinearGradientPattern)
brush = QtGui.QBrush(QtGui.QColor(220,160,50))
else:
gradient = QtGui.QLinearGradient(QtCore.QPointF(0, 0), QtCore.QPointF(0, 20))
gradient.setColorAt(0, QtGui.QColor(55,55,55))
gradient.setColorAt(0.3, QtGui.QColor(60,60,60))
gradient.setColorAt(1, QtGui.QColor(50,50,50))
#brush = QtGui.QBrush(gradient)
#brush.setStyle(QtCore.Qt.LinearGradientPattern)
#brush = QtGui.QBrush(QtGui.QColor(50,50,50))
brush = QtGui.QBrush(QtGui.QColor(32,61,74))
font = QtGui.QFont()
font.setFamily("Helvetica")
font.setStyleStrategy(QtGui.QFont.PreferAntialias)
font.setPointSize(14)
painter.setBrush(brush)
painter.setPen(blackPen)
painter.setFont(font)
painter.drawRoundedRect(self.rect,5,5)
#pen.setColor(QtGui.QColor("white"))
if self.scale > 0.75:
painter.setPen(whitePen)
painter.drawText(self.rect, QtCore.Qt.AlignCenter,self.name())