[PySide] QComboBox - rect of actual menu vs widget area
Frank Rueter | OHUfx
frank at ohufx.com
Sun Dec 23 10:47:07 CET 2018
Here is the basic functional code (to have a QComboBox with integrated
buy bar):
class TaskWidget(QtWidgets.QComboBox):
"""combo box with simple bar animation to indicate that the items
are not ready yet"""
def __init__(self, parent=None):
super(TaskWidget, self).__init__(parent)
self.counter = 0
self.position = 0
self.indicator_width = 20
self.finished = False
self.start_anim()
def start_anim(self):
self.timer_id = self.startTimer(50)
def stop_anim(self):
self.finished = not self.finished
self.killTimer(self.timer_id)
def timerEvent(self, event):
if not self.finished:
self.counter += .2
self.position = ((math.sin(self.counter) + 1) * .5) *
(self.width() - self.indicator_width)
self.update()
def paintEvent(self, event):
super(TaskWidget, self).paintEvent(event)
painter = QtGui.QPainter()
painter.begin(self)
indicator = QtCore.QRect(self.position,0,self.indicator_width,
event.rect().height())
painter.fillRect(indicator, QtCore.Qt.gray)
painter.end()
On 23/12/18 10:03 PM, Frank Rueter | OHUfx wrote:
> Hi,
>
> I am trying to draw a simple busy indicator into a QCombobox while
> it's being populated with items.
> I thought I'd use with a custom paint event that checks is a certain
> condition is true, and if so it will draw custom stuff in to the menu,
> otherwise it just does it's default thing and draw the items as usual.
> This is the bit I started with:
>
> class TaskWidget(QtWidgets.QComboBox):
> def __init__(self, parent=None):
> super(TaskWidget, self).__init__(parent)
>
> def paintEvent(self, event):
> super(TaskWidget, self).paintEvent(event)
> painter = QtGui.QPainter()
> painter.begin(self)
> indicator = QtCore.QRect(0,0,5, event.rect().height())
> painter.fillRect(indicator, QtCore.Qt.red)
> painter.end()
>
> which yields this:
>
> How do I get the (rounded) rectangle of the menu itself though? I.e. I
> only want to draw the red bar inside the menu area that will show the
> items.
>
> I guess I should try to query the item view's rect via it's item
> delegate or something, but I can't get it right.
> Any help would be appreciated.
>
> Happy Christmas!
>
> Cheers,
> frank
>
>
> _______________________________________________
> PySide mailing list
> PySide at qt-project.org
> https://lists.qt-project.org/listinfo/pyside
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20181223/abaf3994/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: oggomkafjjcfdfnc.png
Type: image/png
Size: 67579 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20181223/abaf3994/attachment.png>
More information about the PySide
mailing list