本文整理汇总了Python中AnyQt.QtCore.QRect.width方法的典型用法代码示例。如果您正苦于以下问题:Python QRect.width方法的具体用法?Python QRect.width怎么用?Python QRect.width使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtCore.QRect
的用法示例。
在下文中一共展示了QRect.width方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: paint
# 需要导入模块: from AnyQt.QtCore import QRect [as 别名]
# 或者: from AnyQt.QtCore.QRect import width [as 别名]
def paint(self, painter, option, index):
rect = QRect(option.rect)
is_selected = index.data(VariableSelectionModel.IsSelected)
if option.state & QStyle.State_MouseOver:
txt = [" Add ", " Remove "][is_selected]
txtw = painter.fontMetrics().width(txt)
painter.save()
painter.setPen(Qt.NoPen)
painter.setBrush(QColor("#ccc"))
brect = QRect(rect.x() + rect.width() - 8 - txtw, rect.y(),
txtw, rect.height())
painter.drawRoundedRect(brect, 4, 4)
painter.restore()
painter.drawText(brect, Qt.AlignCenter, txt)
painter.save()
double_pen = painter.pen()
double_pen.setWidth(2 * double_pen.width())
if is_selected:
next = index.sibling(index.row() + 1, index.column())
if not next.isValid():
painter.setPen(double_pen)
painter.drawLine(rect.bottomLeft(), rect.bottomRight())
elif not next.data(VariableSelectionModel.IsSelected):
painter.drawLine(rect.bottomLeft(), rect.bottomRight())
elif not index.row():
down = QPoint(0, painter.pen().width())
painter.setPen(double_pen)
painter.drawLine(rect.topLeft() + down, rect.topRight() + down)
else:
prev = index.sibling(index.row() - 1, index.column())
if prev.data(VariableSelectionModel.IsSelected):
painter.drawLine(rect.topLeft(), rect.topRight())
painter.restore()
super().paint(painter, option, index)
示例2: showPopup
# 需要导入模块: from AnyQt.QtCore import QRect [as 别名]
# 或者: from AnyQt.QtCore.QRect import width [as 别名]
def showPopup(self):
# type: () -> None
"""
Reimplemented from QComboBox.showPopup
Popup up a customized view and filter edit line.
Note
----
The .popup(), .lineEdit(), .completer() of the base class are not used.
"""
if self.__popup is not None:
# We have user entered state that cannot be disturbed
# (entered filter text, scroll offset, ...)
return # pragma: no cover
if self.count() == 0:
return
opt = QStyleOptionComboBox()
self.initStyleOption(opt)
popup = QListView(
uniformItemSizes=True,
horizontalScrollBarPolicy=Qt.ScrollBarAlwaysOff,
verticalScrollBarPolicy=Qt.ScrollBarAsNeeded,
iconSize=self.iconSize(),
)
popup.setFocusProxy(self.__searchline)
popup.setParent(self, Qt.Popup | Qt.FramelessWindowHint)
popup.setItemDelegate(_ComboBoxListDelegate(popup))
proxy = QSortFilterProxyModel(
popup, filterCaseSensitivity=Qt.CaseInsensitive
)
proxy.setFilterKeyColumn(self.modelColumn())
proxy.setSourceModel(self.model())
popup.setModel(proxy)
root = proxy.mapFromSource(self.rootModelIndex())
popup.setRootIndex(root)
self.__popup = popup
self.__proxy = proxy
self.__searchline.setText("")
self.__searchline.setPlaceholderText("Filter...")
self.__searchline.setVisible(True)
self.__searchline.textEdited.connect(proxy.setFilterFixedString)
style = self.style() # type: QStyle
popuprect_origin = style.subControlRect(
QStyle.CC_ComboBox, opt, QStyle.SC_ComboBoxListBoxPopup, self
) # type: QRect
popuprect_origin = QRect(
self.mapToGlobal(popuprect_origin.topLeft()),
popuprect_origin.size()
)
editrect = style.subControlRect(
QStyle.CC_ComboBox, opt, QStyle.SC_ComboBoxEditField, self
) # type: QRect
self.__searchline.setGeometry(editrect)
desktop = QApplication.desktop()
screenrect = desktop.availableGeometry(self) # type: QRect
# get the height for the view
listrect = QRect()
for i in range(min(proxy.rowCount(root), self.maxVisibleItems())):
index = proxy.index(i, self.modelColumn(), root)
if index.isValid():
listrect = listrect.united(popup.visualRect(index))
if listrect.height() >= screenrect.height():
break
window = popup.window() # type: QWidget
window.ensurePolished()
if window.layout() is not None:
window.layout().activate()
else:
QApplication.sendEvent(window, QEvent(QEvent.LayoutRequest))
margins = qwidget_margin_within(popup.viewport(), window)
height = (listrect.height() + 2 * popup.spacing() +
margins.top() + margins.bottom())
popup_size = (QSize(popuprect_origin.width(), height)
.expandedTo(window.minimumSize())
.boundedTo(window.maximumSize())
.boundedTo(screenrect.size()))
popuprect = QRect(popuprect_origin.bottomLeft(), popup_size)
popuprect = dropdown_popup_geometry(
popuprect, popuprect_origin, screenrect)
popup.setGeometry(popuprect)
current = proxy.mapFromSource(
self.model().index(self.currentIndex(), self.modelColumn(),
self.rootModelIndex()))
popup.setCurrentIndex(current)
popup.scrollTo(current, QAbstractItemView.EnsureVisible)
popup.show()
popup.setFocus(Qt.PopupFocusReason)
popup.installEventFilter(self)
popup.viewport().installEventFilter(self)
#.........这里部分代码省略.........
示例3: __layout
# 需要导入模块: from AnyQt.QtCore import QRect [as 别名]
# 或者: from AnyQt.QtCore.QRect import width [as 别名]
def __layout(self):
# position itself over `widget`
widget = self.__widget
if widget is None:
return
alignment = self.__alignment
policy = self.sizePolicy()
if widget.isWindow():
bounds = widget.geometry()
else:
bounds = QRect(widget.mapToGlobal(QPoint(0, 0)),
widget.size())
if self.isWindow():
bounds = bounds
else:
bounds = QRect(self.parent().mapFromGlobal(bounds.topLeft()),
bounds.size())
sh = self.sizeHint()
minsh = self.minimumSizeHint()
minsize = self.minimumSize()
if minsize.isNull():
minsize = minsh
maxsize = bounds.size().boundedTo(self.maximumSize())
minsize = minsize.boundedTo(maxsize)
effectivesh = sh.expandedTo(minsize).boundedTo(maxsize)
hpolicy = policy.horizontalPolicy()
vpolicy = policy.verticalPolicy()
def getsize(hint, minimum, maximum, policy):
if policy == QSizePolicy.Ignored:
return maximum
elif policy & QSizePolicy.ExpandFlag:
return maximum
else:
return max(hint, minimum)
width = getsize(effectivesh.width(), minsize.width(),
maxsize.width(), hpolicy)
heightforw = self.heightForWidth(width)
if heightforw > 0:
height = getsize(heightforw, minsize.height(),
maxsize.height(), vpolicy)
else:
height = getsize(effectivesh.height(), minsize.height(),
maxsize.height(), vpolicy)
size = QSize(width, height)
if alignment & Qt.AlignLeft:
x = bounds.x()
elif alignment & Qt.AlignRight:
x = bounds.right() - size.width()
else:
x = bounds.x() + max(0, bounds.width() - size.width()) // 2
if alignment & Qt.AlignTop:
y = bounds.y()
elif alignment & Qt.AlignBottom:
y = bounds.bottom() - size.height()
else:
y = bounds.y() + max(0, bounds.height() - size.height()) // 2
geom = QRect(QPoint(x, y), size)
self.setGeometry(geom)
示例4: __paintEventNoStyle
# 需要导入模块: from AnyQt.QtCore import QRect [as 别名]
# 或者: from AnyQt.QtCore.QRect import width [as 别名]
def __paintEventNoStyle(self):
p = QPainter(self)
opt = QStyleOptionToolButton()
self.initStyleOption(opt)
fm = QFontMetrics(opt.font)
palette = opt.palette
# highlight brush is used as the background for the icon and background
# when the tab is expanded and as mouse hover color (lighter).
brush_highlight = palette.highlight()
foregroundrole = QPalette.ButtonText
if opt.state & QStyle.State_Sunken:
# State 'down' pressed during a mouse press (slightly darker).
background_brush = brush_darker(brush_highlight, 110)
foregroundrole = QPalette.HighlightedText
elif opt.state & QStyle.State_MouseOver:
background_brush = brush_darker(brush_highlight, 95)
foregroundrole = QPalette.HighlightedText
elif opt.state & QStyle.State_On:
background_brush = brush_highlight
foregroundrole = QPalette.HighlightedText
else:
# The default button brush.
background_brush = palette.button()
rect = opt.rect
icon_area_rect = QRect(rect)
icon_area_rect.setRight(int(icon_area_rect.height() * 1.26))
text_rect = QRect(rect)
text_rect.setLeft(icon_area_rect.right() + 10)
# Background (TODO: Should the tab button have native
# toolbutton shape, drawn using PE_PanelButtonTool or even
# QToolBox tab shape)
# Default outline pen
pen = QPen(palette.color(QPalette.Mid))
p.save()
p.setPen(Qt.NoPen)
p.setBrush(QBrush(background_brush))
p.drawRect(rect)
# Draw the background behind the icon if the background_brush
# is different.
if not opt.state & QStyle.State_On:
p.setBrush(brush_highlight)
p.drawRect(icon_area_rect)
# Line between the icon and text
p.setPen(pen)
p.drawLine(icon_area_rect.topRight(),
icon_area_rect.bottomRight())
if opt.state & QStyle.State_HasFocus:
# Set the focus frame pen and draw the border
pen = QPen(QColor(FOCUS_OUTLINE_COLOR))
p.setPen(pen)
p.setBrush(Qt.NoBrush)
# Adjust for pen
rect = rect.adjusted(0, 0, -1, -1)
p.drawRect(rect)
else:
p.setPen(pen)
# Draw the top/bottom border
if self.position == QStyleOptionToolBox.OnlyOneTab or \
self.position == QStyleOptionToolBox.Beginning or \
self.selected & \
QStyleOptionToolBox.PreviousIsSelected:
p.drawLine(rect.topLeft(), rect.topRight())
p.drawLine(rect.bottomLeft(), rect.bottomRight())
p.restore()
p.save()
text = fm.elidedText(opt.text, Qt.ElideRight, text_rect.width())
p.setPen(QPen(palette.color(foregroundrole)))
p.setFont(opt.font)
p.drawText(text_rect,
int(Qt.AlignVCenter | Qt.AlignLeft) | \
int(Qt.TextSingleLine),
text)
if not opt.icon.isNull():
if opt.state & QStyle.State_Enabled:
mode = QIcon.Normal
else:
mode = QIcon.Disabled
if opt.state & QStyle.State_On:
state = QIcon.On
else:
state = QIcon.Off
icon_area_rect = icon_area_rect
icon_rect = QRect(QPoint(0, 0), opt.iconSize)
#.........这里部分代码省略.........