A turntable player

110 views
Skip to first unread message

Panupat Chongstitwattana

unread,
Jun 22, 2018, 6:06:42 AM6/22/18
to Python Programming for Autodesk Maya
Hi.

I'm trying to create a turntable viewer and in need of some guidance please. In this view, I want to be able to click and hold left mouse button then drag left/right to turn the turntable, which are image sequences.

My questions:

- Is there other way I should approach this? The mouse move event triggers too fast and when I try to print out new image names they appear too rapidly.

- How can I detect if I am moving mouse left or right?

- The pixmap doesn't seem to repaint even if I explicitly tells it to.

Appreciate any help. Thank you!
turn3.jpg
turn4.jpg
turntable.py
turn1.jpg
turn2.jpg

Marcus Ottosson

unread,
Jun 22, 2018, 6:16:30 AM6/22/18
to python_in...@googlegroups.com
Here's what I'd do.

1. On mouse press, capture the position of the mouse and register that "scrubbing mode" is active.
2. When scrubbing mode is active, in your `mouseMoveEvent` compare the current position to the one stored on mouse press
3. The distance (e.g. Manhattan length) is how much to scrub.
4. If the delta is positive, then you're scrubbing to the right. Negative means scrubbing to the left.
5. On mouse release, disable scrubbing mode.

This should help produce a smooth and predictable scrubbing behaviour.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/d0541c00-46a5-42da-9cef-36e66ae76813%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Panupat Chongstitwattana

unread,
Jun 25, 2018, 1:42:57 AM6/25/18
to Python Programming for Autodesk Maya
Thank you for your suggestion Marcus.

I added MouseButtonPress and MouseButtonRelease event based on your suggestion and it almost work. I cannot get the image to repaint. It prints out the image name correctly however.

I way to get the repaint working is to remove return True (line 51) from the eventFilter method, but then it would produce error about eventFilter wanting a boolean result over and over.

# -*- coding: utf-8 -*-
import sys
from os.path import dirname, realpath, join
from PySide.QtGui import (QApplication, QVBoxLayout, QLabel, QPixmap,
    QWidget)
from PySide import QtCore


class PlayTurntable(QWidget):
    def __init__(self, images, mouse_threshold=50, parent=None):
        super(PlayTurntable, self).__init__(parent)

        self.label = QLabel()
        self.label.setFixedWidth(300)
        self.label.setFixedHeight(200)
        layout = QVBoxLayout()
        layout.addWidget(self.label)
        self.setLayout(layout)

        # init variables
        self.tracking = False
        self.mouse_start = 0
        self.mouse_threshold = mouse_threshold
        self.images = images
        self.image_index = 0
        self.pic = QPixmap(self.images[self.image_index])
        self.label.setPixmap(self.pic.scaled(300, 200, QtCore.Qt.KeepAspectRatio))
        self.installEventFilter(self)

    def eventFilter(self, obj, event):
        if event.type() == event.MouseButtonPress:
            if event.button() == QtCore.Qt.LeftButton:
                self.mouse_start = event.x()
                self.tracking = True
                event.accept()
        if event.type() == event.MouseButtonRelease:
            if event.button() == QtCore.Qt.LeftButton:
                self.tracking = False
                event.accept()
        if event.type() == event.MouseMove:
            if self.tracking:
                mouse_x = event.x()
                distance = self.mouse_start - mouse_x
                if abs(distance) >= self.mouse_threshold:
                    self.mouse_start = mouse_x
                    if distance > 0:
                        self.frame_step(1)
                    else:
                        self.frame_step(-1)
                event.accept()
        return True

    def frame_step(self, amount):
        self.image_index += amount
        if self.image_index >= len(self.images):
            self.image_index = 0
        elif self.image_index < 0:
            self.image_index = len(self.images) - 1
        print 'switching to: %s' % self.images[self.image_index]

        self.pic.load(self.images[self.image_index])
        self.label.setPixmap(
            self.pic.scaled(300, 200, QtCore.Qt.KeepAspectRatio))
        self.label.repaint()


if __name__=='__main__':
    current_path = dirname(realpath(__file__))
    images = ['turn1.jpg', 'turn2.jpg', 'turn3.jpg', 'turn4.jpg']
    for index, value in enumerate(images):
        images[index] = join(current_path, value)

    app = QApplication(sys.argv)
    PT = PlayTurntable(images)
    PT.show()
    sys.exit(app.exec_())


Panupat Chongstitwattana

unread,
Jun 25, 2018, 2:18:32 AM6/25/18
to Python Programming for Autodesk Maya
Got it working now with more returns added to the eventFilter.

def eventFilter(self, obj, event):
if event.type() == event.MouseButtonPress:
if event.button() == QtCore.Qt.LeftButton:
self.mouse_start = event.x()
self.tracking = True
event.accept()
            return True
    if event.type() == event.MouseButtonRelease:
if event.button() == QtCore.Qt.LeftButton:
self.tracking = False
event.accept()
            return True
    if event.type() == event.MouseMove:
if self.tracking:
mouse_x = event.x()
distance = self.mouse_start - mouse_x
if abs(distance) >= self.mouse_threshold:
self.mouse_start = mouse_x
if distance > 0:
self.frame_step(1)
else:
self.frame_step(-1)
event.accept()
return True
    return False

Marcus Ottosson

unread,
Jun 25, 2018, 2:44:19 AM6/25/18
to python_in...@googlegroups.com

Using an event filter is a little heavy handed for what you’re trying to achieve, I think.

The problem with it is that every event, including draw events, passes through your event filter waiting for it to either block the event - return True - or pass it through - return False. And the number of events can be quite a lot - sometimes tens of thousands of events per second.

An alternative is to instead override mousePressEvent, mouseReleaseEvent and mouseMoveEvent. That way you wouldn’t inadvertently interfere with events you aren’t interested in, and handling them would remain quick even as complexity increases.


To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

Panupat Chongstitwattana

unread,
Jun 25, 2018, 2:57:56 AM6/25/18
to Python Programming for Autodesk Maya
Thank you Marcus. Here's the updated methods and it's working as intended.

def mousePressEvent(self, event):
    if event.button() == QtCore.Qt.LeftButton:
self.mouse_start = event.x()
self.tracking = True

def mouseReleaseEvent(self, event):
    if event.button() == QtCore.Qt.LeftButton:
self.tracking = False

def mouseMoveEvent(self, event):
    if self.tracking:
mouse_x = event.x()
distance = self.mouse_start - mouse_x
if abs(distance) >= self.mouse_threshold:
self.mouse_start = mouse_x
if distance > 0:
self.frame_step(1)
else:
self.frame_step(-1)

A little question please. From some example I saw, they would also add this line to the events.

super(ClassName, self).mousePressEvent(event)

in what instances would you want, or need, to do that?
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/d0541c00-46a5-42da-9cef-36e66ae76813%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Marcus Ottosson

unread,
Jun 25, 2018, 3:14:36 AM6/25/18
to python_in...@googlegroups.com

You are most welcome.

in what instances would you want, or need, to do that?

If you’re inheriting from a class that already subclasses those, it’d be useful for when you want to add to the original behavior. Otherwise you’d be replacing it. For example, anyone inheriting from the class you’re just made may want to call that so as to still be able to get the scrubbing functionality.

Sometimes you may want to call it because the superclass has implemented something for it. For example, overriding the closeEvent and not calling its superclass would override - and thus block - the GUI from closing. I’m not entirely sure when and why event handlers require this, so I make it a habit out of always calling it for Qt events.


To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

Panupat Chongstitwattana

unread,
Jun 25, 2018, 3:19:52 AM6/25/18
to Python Programming for Autodesk Maya
I see. Does it matter if you call super first thing or last thing in the method override?
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

Marcus Ottosson

unread,
Jun 25, 2018, 3:30:29 AM6/25/18
to python_in...@googlegroups.com

Sometimes. In the case of closeEvent, calling it would close the GUI I think so you’d probably want your code to run first. In general, it depends on whether you want something done before or after the superclass implementation. In your case, someone overriding your mouseMoveEvent would have to decide whether the code should run before or after performing the scrubbing. Sometimes it doesn’t matter, sometimes it does.


To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

Justin Israel

unread,
Jun 25, 2018, 4:39:18 AM6/25/18
to python_in...@googlegroups.com
One last tip about the event handlers. It might be good for you to make use of if/elif instead of comparing extra cases that will never be true since another event is going to match. It's just wasteful comparisons. 

Justin 

To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOAVMYnb-M3uZyfPuV4NXnwpsChQXgaGG%3DzKE7W2VHE2og%40mail.gmail.com.

Panupat Chongstitwattana

unread,
Jun 25, 2018, 8:32:18 AM6/25/18
to Python Programming for Autodesk Maya
Thank you for your suggestion Justin. Did you mean the mouseMoveEvent method? Made some adjustments and is working as intended.

def mouseMoveEvent(self, event):
if not self.tracking:
return
distance = self.mouse_start - event.x()
if distance >= self.mouse_threshold:
self.mouse_start = event.x()
self.frame_step(1)
elif distance <= -self.mouse_threshold:
self.mouse_start = event.x()
self.frame_step(-1)
Justin 

To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

Panupat Chongstitwattana

unread,
Jun 25, 2018, 8:39:45 AM6/25/18
to Python Programming for Autodesk Maya
Question on Pixmap resizing.

I tried switching from fixed size to allow resizing.
This is what I have at the moment and what happens is that I can increase my widget size,
but it won't let me decrease. How should I approach this?

in __init__
self.pic = QPixmap(self.images[self.image_index])
# self.label.setScaledContents(True)
# self.label.setPixmap(self.pic.scaled(300, 200, QtCore.Qt.KeepAspectRatio))
self.label.setPixmap(
self.pic.scaled(self.label.width(), self.label.height(), QtCore.Qt.KeepAspectRatio))

and an event override.
def resizeEvent(self, event):
self.label.setPixmap(
self.pic.scaled(self.label.width(), self.label.height(),
QtCore.Qt.KeepAspectRatio))

Justin Israel

unread,
Jun 25, 2018, 3:47:54 PM6/25/18
to python_in...@googlegroups.com


On Tue, Jun 26, 2018, 12:32 AM Panupat Chongstitwattana <panu...@gmail.com> wrote:
Thank you for your suggestion Justin. Did you mean the mouseMoveEvent method? Made some adjustments and is working as intended.

Yep, that was what I meant. In a previous example you had alot of repeat checking of the event type in your eventFilter. But it will only be one type. 

To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/d693a6e7-34b3-4724-9281-03fdc6f39abf%40googlegroups.com.

Justin Israel

unread,
Jun 25, 2018, 3:49:13 PM6/25/18
to python_in...@googlegroups.com


On Tue, Jun 26, 2018, 12:39 AM Panupat Chongstitwattana <panu...@gmail.com> wrote:
Question on Pixmap resizing.

I tried switching from fixed size to allow resizing.
This is what I have at the moment and what happens is that I can increase my widget size,
but it won't let me decrease. How should I approach this?

Try self.label.setMinimumSize(minX, minY) 

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/28081328-02ff-4d9a-b94b-77003355dbef%40googlegroups.com.
Message has been deleted

Panupat Chongstitwattana

unread,
Jun 26, 2018, 12:33:46 AM6/26/18
to Python Programming for Autodesk Maya
Thank you Justin. Wow so by setting minimal size it allows going smaller. I wouldn't have suspected that.

By the way is it OK to call setPixmap over and over like I did in resizeEvent? It seems a bit redundant.

def resizeEvent(self, event):
self.label.setPixmap(
self.pic.scaled(self.label.width(), self.label.height(),
QtCore.Qt.KeepAspectRatio))

But I tried doing self.pic.scaled and self.label.repaint but those 2 didn't seem to do anything.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

Justin Israel

unread,
Jun 26, 2018, 1:40:30 AM6/26/18
to python_in...@googlegroups.com
self.pic.scaled() returns a new scalled QPixmap instance. So calling it the way you doing is having no actual effect. You aren't doing anything with the return value. That is why you have to pass a new scaled QPixmap into the QLabel, which retains the aspect ratio.

Justin


To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/5cc87977-3e14-4c08-9b08-4125765feba9%40googlegroups.com.

Panupat Chongstitwattana

unread,
Jun 26, 2018, 2:17:43 AM6/26/18
to Python Programming for Autodesk Maya
I see. Thank you again Justin.

Moving to another functionality. I want to add a default icon with lowered opacity when calling without passing images attribute. It is hard-coded right now.

if not images or not isinstance(images, list):
self.disable = True
self.images = [join(dirname(realpath(__file__)), 'mystery2.png')]
    self.pic = QPixmap(self.images[self.image_index])

In order to make it translucent I need to use QPainter right? How does it work. Does it replace QPixmap entirely?
By adding this into paintEvent I get a duplicate image with lowered opacity stuck static to the widget.

def paintEvent(self, event):
if self.disable:
painter = QPainter()
painter.begin(self)
painter.setOpacity(0.3)
painter.drawPixmap(0,0, self.pic)
painter.end()
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
6_26_2018 , 1_17_16 PM.jpg

Justin Israel

unread,
Jun 26, 2018, 3:17:59 AM6/26/18
to python_in...@googlegroups.com
You have two options two choose from, but you are actually currently doing a mixture of both.

1) use a QPainter(self) (as per your example) and paint the icon manually, from your stored self.pic. If you do this, you need to not set the pixmap onto the QLabel, otherwise you will get the paint logic from the QLabel plus your own extra painting of the image again.

2) use a QPainter(newPixmap) to paint your self.pic into a new QPixmap that is semi-transparent. Then set this new pixmap instance onto your QLabel and let its default painting logic handle drawing it

QPainter generally allows you to paint onto objects that are QPainDevice instances (QWidget, QPixmap, ...). When you override a paintEvent, you are handling the drawing onto the widget directly. But you can just as easily draw into a pixmap.

Justin

To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/0f4b69b5-2a4c-483e-8c94-1486441e72fe%40googlegroups.com.

Panupat Chongstitwattana

unread,
Jun 26, 2018, 4:23:04 AM6/26/18
to Python Programming for Autodesk Maya
Thank you everyone for your help. Learned a lot from this simple widget.

My current working code. If there's any room for adjustment please let me know :)
Been thinking that it would be great to pre-load image sequences in advance.
Maybe create pixmap for each of them and store in a list?

# -*- coding: utf-8 -*-
import sys
from os.path import dirname, realpath, join
from PySide.QtGui import (QApplication, QVBoxLayout, QLabel, QPixmap, QWidget,
QPainter)
from PySide import QtCore


class ScrubbaleImageSequenceWidget(QWidget):
""" Exercize. A widget that users can scrub to play the turntable image
sequence.

Note: Try to pre-load the sequence into a list of pixmap?

Args:
images (str list): Full path to sequential images.
mouse_threshold (int): Scrub distance for image change.

Attributes:
disable (bool): stop the Widget from doing anything
tracking (bool): A switch to tell Widget when to track mouse movement.
mouse_start (float): Mouse starting X position.
image_index (int): Current index of image displaying.
image_opacity (float): Image opacity.

"""
def __init__(self, images = None, mouse_threshold=30, parent=None):
super(ScrubbaleImageSequenceWidget, self).__init__(parent)
self.images = images
self.mouse_threshold = mouse_threshold
self.disable = False
        self.tracking = False
self.mouse_start = 0
        self.image_index = 0
self.image_opacity = 1.0

self.setMinimumSize(100, 50)
self.resize(250, 200)
self.label = QLabel()
self.label.setAlignment(QtCore.Qt.AlignCenter)
layout = QVBoxLayout()
layout.setContentsMargins(10, 10, 10, 10)
layout.addWidget(self.label)
self.setLayout(layout)

if not images or not isinstance(images, list):
self.disable = True
            self.image_opacity = 0.2
            self.images = [join(dirname(realpath(__file__)), 'mystery2.png')]
self.pic = QPixmap(self.images[self.image_index])

    def mousePressEvent(self, event):
if self.disable:
return
        if event.button() == QtCore.Qt.LeftButton:
self.mouse_start = event.x()
self.tracking = True
        print 'UI size ', self.width(), self.height()
print 'label size ', self.label.width(), self.label.height()

def mouseReleaseEvent(self, event):
if self.disable:
return
        if event.button() == QtCore.Qt.LeftButton:
self.tracking = False

def mouseMoveEvent(self, event):
        if self.disable:
return
        if not self.tracking:
return
distance = self.mouse_start - event.x()
if distance >= self.mouse_threshold:
self.mouse_start = event.x()
self.frame_step(1)
elif distance <= -self.mouse_threshold:
self.mouse_start = event.x()
self.frame_step(-1)

    def frame_step(self, amount):
# update and loop the image index
        self.image_index += amount
if self.image_index >= len(self.images):
self.image_index = 0
elif self.image_index < 0:
self.image_index = len(self.images) - 1

        self.pic.load(self.images[self.image_index])
self.repaint()

def paintEvent(self, event):
painter = QPainter()
painter.begin(self)
painter.setOpacity(self.image_opacity)
scaled_pic = self.pic.scaled(self.label.width(),
self.label.height(),
QtCore.Qt.KeepAspectRatio,
QtCore.Qt.SmoothTransformation,)
x_offset = (self.width() - scaled_pic.width()) / 2
y_offset = (self.height() - scaled_pic.height()) / 2
painter.drawPixmap(x_offset, y_offset, scaled_pic)
painter.end()

if __name__=='__main__':
current_path = dirname(realpath(__file__))
    images = []
for i in range(1,8):
images.append('%s/turn%s.jpg' % (current_path, i))
app = QApplication(sys.argv)
# PT = ScrubbaleImageSequenceWidget(images)
PT = ScrubbaleImageSequenceWidget('random string')
PT.show()
sys.exit(app.exec_())
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

Panupat Chongstitwattana

unread,
Jun 26, 2018, 4:47:41 AM6/26/18
to Python Programming for Autodesk Maya
By the way I went with QPainter because it's the only way I could find how to control opacity. Is opacity possible if I use QPixmap?

Justin Israel

unread,
Jun 26, 2018, 5:37:22 AM6/26/18
to python_in...@googlegroups.com
QPixmapCache is a good candidate if you want to preload your images. There is already a global cache that gets used anyways when you load QPixmaps from files. You can insert them ahead of time if you want: https://doc-snapshots.qt.io/qtforpython/PySide2/QtGui/QPixmapCache.html
When you load your app, you can insert the images. Then as you need them you find them from the cache and it will serve them out of memory. 

Using QPainter is the right way to draw a translucent image.

Justin


On Tue, Jun 26, 2018 at 8:47 PM Panupat Chongstitwattana <panu...@gmail.com> wrote:
By the way I went with QPainter because it's the only way I could find how to control opacity. Is opacity possible if I use QPixmap?

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/015699b1-1b03-47d8-93b2-ed0551cd2ce8%40googlegroups.com.

Panupat Chongstitwattana

unread,
Jun 26, 2018, 5:39:21 AM6/26/18
to Python Programming for Autodesk Maya
Ran into a problem. When I set qdarkstyle, the images no longer showed up. Neither load_stylesheet nor load_stylesheet_pyside worked.

environ['QT_API'] = 'pyside'

app = QApplication(sys.argv)
app.setStyleSheet(qdarkstyle.load_stylesheet())
SCRUB = ScrubbaleImageSequenceWidget(images)
# SCRUB = ScrubbaleImageSequenceWidget('random string')
SCRUB.show()
sys.exit(app.exec_())



Panupat Chongstitwattana

unread,
Jun 27, 2018, 3:11:43 AM6/27/18
to Python Programming for Autodesk Maya
Figured another one out thanks to Stackoverflow.


My paintEvent was done on QWidget, which was behind QLabel. Once the QLabel got stylesheet'd it covered up my image I suppose. So paintEvent needed to be implemented on the QLabel instead.

Attached is a working code. Not sure how many methods I should keep in QWidget class vs move to QLabel class but here is what I have.

Next step I'll try out QPixmapCache.



turntable.py
Auto Generated Inline Image 1
Reply all
Reply to author
Forward
0 new messages