From frank at ohufx.com Thu Aug 4 06:31:37 2016 From: frank at ohufx.com (Frank Rueter | OHUfx) Date: Thu, 4 Aug 2016 16:31:37 +1200 Subject: [PySide] can a QStandardItem emit a signal? Message-ID: Hi, I am writing a custom view for a simple data model and need to have a custom widget change it's background colour when it's associated QStandardItem has a certain attribute. I thought I'd simply subclass QStandardItem, give it the custom attribute, e.g. isSelected, then a method called setSelected() which sets the attribute's value and emits a selectionChanged signal, to which I can connect the associated widget's slot that changes the background colour. So this is what I have for the item: class ElemItem(QtGui.QStandardItem): selectionChanged = QtCore.Signal(bool) def __init__(self, elementData): super(ElemItem, self).__init__(elementData) self.isSelected = False self.filePath = elementData def setSelected(self, selected): self.isSelected = selected selectionChanged.emit(selected) However, since QStandardItem doesn't inherit QObject it doesn't seem to be able to emit a signal. When I try something like this in the widget: self.item.selectionChanged.connect(self.markAsSelected) I get this error: AttributeError: 'PySide.QtCore.Signal' object has no attribute 'connect' Is this the entirely wrong way of achieving what I'm after? I can achieve what I'm after in other ways but would like to understand this hiccup before moving on, so any input would be welcome. Cheers, frank -- ohufxLogo 50x50 *vfx compositing | *workflow customisation and consulting * * -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: ohufxLogo_50x50.png Type: image/png Size: 2666 bytes Desc: not available URL: From chgans at gna.org Thu Aug 4 13:26:12 2016 From: chgans at gna.org (Ch'Gans) Date: Thu, 4 Aug 2016 23:26:12 +1200 Subject: [PySide] can a QStandardItem emit a signal? In-Reply-To: References: Message-ID: Only QObjects can emit signals. If you want to get notification when the selected item(s) changes, then you need to connect to the view's selection model: http://doc.qt.io/qt-5/qabstractitemview.html#selectionModel I don't see any reason why C++ should be different from python on this topic. Chris On 4 August 2016 at 16:31, Frank Rueter | OHUfx wrote: > Hi, > > I am writing a custom view for a simple data model and need to have a > custom widget change it's background colour when it's associated > QStandardItem has a certain attribute. > I thought I'd simply subclass QStandardItem, give it the custom attribute, > e.g. isSelected, then a method called setSelected() which sets the > attribute's value and emits a selectionChanged signal, to which I can > connect the associated widget's slot that changes the background colour. > So this is what I have for the item: > > class ElemItem(QtGui.QStandardItem): > selectionChanged = QtCore.Signal(bool) > > def __init__(self, elementData): > super(ElemItem, self).__init__(elementData) > self.isSelected = False > self.filePath = elementData > > def setSelected(self, selected): > self.isSelected = selected > selectionChanged.emit(selected) > > > However, since QStandardItem doesn't inherit QObject it doesn't seem to be > able to emit a signal. When I try something like this in the widget: > self.item.selectionChanged.connect(self.markAsSelected) > > I get this error: > AttributeError: 'PySide.QtCore.Signal' object has no attribute > 'connect' > > > Is this the entirely wrong way of achieving what I'm after? > I can achieve what I'm after in other ways but would like to understand > this hiccup before moving on, so any input would be welcome. > > Cheers, > frank > > > > -- > [image: ohufxLogo 50x50] *vfx compositing > | workflow customisation and > consulting * > > _______________________________________________ > PySide mailing list > PySide at qt-project.org > http://lists.qt-project.org/mailman/listinfo/pyside > > -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: ohufxLogo_50x50.png Type: image/png Size: 2666 bytes Desc: not available URL: From bazwal at gmail.com Thu Aug 4 17:30:19 2016 From: bazwal at gmail.com (Baz Walter) Date: Thu, 4 Aug 2016 16:30:19 +0100 Subject: [PySide] can a QStandardItem emit a signal? In-Reply-To: References: Message-ID: On 04/08/16 05:31, Frank Rueter | OHUfx wrote: > Hi, > > I am writing a custom view for a simple data model and need to have a > custom widget change it's background colour when it's associated > QStandardItem has a certain attribute. I thought I'd simply subclass > QStandardItem, give it the custom attribute, e.g. isSelected, then a > method called setSelected() which sets the attribute's value and > emits a selectionChanged signal, to which I can connect the > associated widget's slot that changes the background colour. So this > is what I have for the item: > > class ElemItem(QtGui.QStandardItem): selectionChanged = > QtCore.Signal(bool) > > def __init__(self, elementData): super(ElemItem, > self).__init__(elementData) self.isSelected = False self.filePath = > elementData > > def setSelected(self, selected): self.isSelected = selected > selectionChanged.emit(selected) > > > However, since QStandardItem doesn't inherit QObject it doesn't seem > to be able to emit a signal. When I try something like this in the > widget: self.item.selectionChanged.connect(self.markAsSelected) > > I get this error: AttributeError: 'PySide.QtCore.Signal' object has > no attribute 'connect' > > > Is this the entirely wrong way of achieving what I'm after? I can > achieve what I'm after in other ways but would like to understand > this hiccup before moving on, so any input would be welcome. Yes, it is the wrong way. There is already an API that *almost* does exactly what you want. If the item has been added to a model, its setData() method will emit the model's itemChanged signal whenever the value of the data changes. However, this signal is quite poorly designed, because although it sends the *item* that changed, it does not also send the *role* that changed. If it did the latter, you could just set your special attribute using a custom role, and then test for that role in a slot connected to the model's itemChanged signal. It's really a shame that the existing API doesn't work as it should, but it shouldn't be too difficult to add a similar API of your own that does the right thing. The key is to use the QStandardItem.model() method to get access to the parent model (which would then allow you to emit a custom signal defined on that model). -- Regards Baz Walter From frank at ohufx.com Thu Aug 4 23:29:29 2016 From: frank at ohufx.com (Frank Rueter | OHUfx) Date: Fri, 5 Aug 2016 09:29:29 +1200 Subject: [PySide] can a QStandardItem emit a signal? In-Reply-To: References: Message-ID: Thanks guys, I did get it to work but will try and refactor to use the model's signals to learn better habits. Cheers, frank On 5/08/16 3:30 AM, Baz Walter wrote: > On 04/08/16 05:31, Frank Rueter | OHUfx wrote: >> Hi, >> >> I am writing a custom view for a simple data model and need to have a >> custom widget change it's background colour when it's associated >> QStandardItem has a certain attribute. I thought I'd simply subclass >> QStandardItem, give it the custom attribute, e.g. isSelected, then a >> method called setSelected() which sets the attribute's value and >> emits a selectionChanged signal, to which I can connect the >> associated widget's slot that changes the background colour. So this >> is what I have for the item: >> >> class ElemItem(QtGui.QStandardItem): selectionChanged = >> QtCore.Signal(bool) >> >> def __init__(self, elementData): super(ElemItem, >> self).__init__(elementData) self.isSelected = False self.filePath = >> elementData >> >> def setSelected(self, selected): self.isSelected = selected >> selectionChanged.emit(selected) >> >> >> However, since QStandardItem doesn't inherit QObject it doesn't seem >> to be able to emit a signal. When I try something like this in the >> widget: self.item.selectionChanged.connect(self.markAsSelected) >> >> I get this error: AttributeError: 'PySide.QtCore.Signal' object has >> no attribute 'connect' >> >> >> Is this the entirely wrong way of achieving what I'm after? I can >> achieve what I'm after in other ways but would like to understand >> this hiccup before moving on, so any input would be welcome. > > Yes, it is the wrong way. There is already an API that *almost* does > exactly what you want. If the item has been added to a model, its > setData() method will emit the model's itemChanged signal whenever the > value of the data changes. However, this signal is quite poorly > designed, because although it sends the *item* that changed, it does > not also send the *role* that changed. If it did the latter, you could > just set your special attribute using a custom role, and then test for > that role in a slot connected to the model's itemChanged signal. > > It's really a shame that the existing API doesn't work as it should, > but it shouldn't be too difficult to add a similar API of your own > that does the right thing. The key is to use the QStandardItem.model() > method to get access to the parent model (which would then allow you > to emit a custom signal defined on that model). > > -- > Regards > Baz Walter From dc.loco at gmail.com Fri Aug 5 15:57:57 2016 From: dc.loco at gmail.com (Kevin Cole) Date: Fri, 5 Aug 2016 09:57:57 -0400 Subject: [PySide] SVG image follow mouse w/o drag and drop? Message-ID: Hi, I'm trying to understand graphics items, scenes, views, widgets, and not doing so well. I posted a question over on Stack Overflow, but probably should have tried here first. The question, copied below, is from http://stackoverflow.com/questions/38749882/pyside-have-an-svg-image-follow-mouse-without-drag-and-drop I'm trying to place an SVG image in what will eventually be a QGroupBox in another application. Then, upon the first click over the SVG, the SVG "sticks" to the mouse (as if the mouse button was held down during a drag and drop). A second click will release ("drop") the image. I've been reading but not quite understanding the nature of / relationship between Widgets, Items, Scenes and Views. My code below sort of works but isn't quite right. The image almost actively avoids the mouse. Is there a clear explanation somewhere for non-C, non-C++, beginners with PyQt / PySide? Or is there a simple explanation for where I've gone wrong? #!/usr/bin/env python2 # -*- coding: utf-8 -*- import sys from PySide.QtCore import * from PySide.QtGui import * from PySide.QtSvg import * class Image(QGraphicsSvgItem): def __init__(self, parent=None): super(Image, self).__init__("image.svg", parent) self.parent = parent self.setFlags(QGraphicsItem.ItemIsSelectable | QGraphicsItem.ItemIsMovable) self.setAcceptsHoverEvents(True) self.svgSize = self.renderer().defaultSize() self.width = self.svgSize.width() self.height = self.svgSize.height() self.absolute = None # Image's absolute (global) position self.mobile = 0 # Initially immobile self.scene = None # Not in a scene yet self.view = None # Not in a view yet def hoverEnterEvent(self, event): print "Enter" def hoverLeaveEvent(self, event): print "Leave" def hoverMoveEvent(self, event): print "Moving" self.absolute = QCursor.pos() if self.view: relative = self.view.mapFromGlobal(self.absolute) if self.mobile: # self.setPos(relative) self.setPos(self.absolute) class Viewport(QGraphicsView): def __init__(self, parent=None): super(Viewport, self).__init__(parent) self.scene = QGraphicsScene() self.image = Image() self.image.setPos(100, 100) self.scene.addItem(self.image) self.setScene(self.scene) self.image.scene = self.scene self.image.view = self def mousePressEvent(self, event): super(Viewport, self).mousePressEvent(event) self.image.mobile = (self.image.mobile + 1) % 2 # Toggle mobility x = self.image.x() # + int(self.image.width / 2) y = self.image.y() # + int(self.image.height / 2) QCursor.setPos(x, y) relative = self.mapFromGlobal(self.image.absolute) print "absolute.x() = {0} absolute.y() = {1}"\ .format(self.image.absolute.x(), self.image.absolute.y()) print "relative.x() = {0} relative.y() = {1}"\ .format(relative.x(), relative.y()) class MainWindow(QWidget): def __init__(self, parent=None): super(MainWindow, self).__init__(parent) self.view = Viewport(self) hbox = QHBoxLayout() hbox.addWidget(self.view) self.setLayout(hbox) app = QApplication(sys.argv) window = MainWindow() window.show() sys.exit(app.exec_()) From jukka.purma at aalto.fi Fri Aug 5 17:13:49 2016 From: jukka.purma at aalto.fi (Purma Jukka) Date: Fri, 5 Aug 2016 15:13:49 +0000 Subject: [PySide] SVG image follow mouse w/o drag and drop? In-Reply-To: <10039_1470405485_57A49B6C_10039_12_2_CA+pvXRe3Sws-LbX7OpMWZp=a2zzR4AuMFNsV9Zbs34_CN1a5cQ@mail.gmail.com> References: <10039_1470405485_57A49B6C_10039_12_2_CA+pvXRe3Sws-LbX7OpMWZp=a2zzR4AuMFNsV9Zbs34_CN1a5cQ@mail.gmail.com> Message-ID: Hi, You don’t have to do anything in QGraphicsView, you can have mousePressEvent in Image to toggle floating on and off. These events get QGraphicsMouseEvents as parameters and these have the information you need about position of cursor or mouse press. So, in short, remove mousePressEvent from viewPort and replace hoverMoveEvent in your Image with this and it will work: def hoverMoveEvent(self, event): if self.mobile: print("Moving") self.setPos(event.scenePos() - QPoint(self.width / 2, self.height / 2)) def mousePressEvent(self, event): self.mobile = not self.mobile # Toggle mobility super().mousePressEvent(event) Jukka > Kevin Cole kirjoitti 5.8.2016 kello 16.57: > > Hi, > > I'm trying to understand graphics items, scenes, views, widgets, and > not doing so well. I posted a question over on Stack Overflow, but > probably should have tried here first. > > The question, copied below, is from > http://stackoverflow.com/questions/38749882/pyside-have-an-svg-image-follow-mouse-without-drag-and-drop > > I'm trying to place an SVG image in what will eventually be a > QGroupBox in another application. Then, upon the first click over the > SVG, the SVG "sticks" to the mouse (as if the mouse button was held > down during a drag and drop). A second click will release ("drop") the > image. > > I've been reading but not quite understanding the nature of / > relationship between Widgets, Items, Scenes and Views. My code below > sort of works but isn't quite right. The image almost actively avoids > the mouse. Is there a clear explanation somewhere for non-C, non-C++, > beginners with PyQt / PySide? Or is there a simple explanation for > where I've gone wrong? > > #!/usr/bin/env python2 > # -*- coding: utf-8 -*- > > import sys > from PySide.QtCore import * > from PySide.QtGui import * > from PySide.QtSvg import * > > > class Image(QGraphicsSvgItem): > > def __init__(self, parent=None): > super(Image, self).__init__("image.svg", parent) > self.parent = parent > > self.setFlags(QGraphicsItem.ItemIsSelectable | > QGraphicsItem.ItemIsMovable) > > self.setAcceptsHoverEvents(True) > > self.svgSize = self.renderer().defaultSize() > self.width = self.svgSize.width() > self.height = self.svgSize.height() > self.absolute = None # Image's absolute (global) position > self.mobile = 0 # Initially immobile > self.scene = None # Not in a scene yet > self.view = None # Not in a view yet > > def hoverEnterEvent(self, event): > print "Enter" > > def hoverLeaveEvent(self, event): > print "Leave" > > def hoverMoveEvent(self, event): > print "Moving" > self.absolute = QCursor.pos() > if self.view: > relative = self.view.mapFromGlobal(self.absolute) > if self.mobile: > # self.setPos(relative) > self.setPos(self.absolute) > > > class Viewport(QGraphicsView): > > def __init__(self, parent=None): > super(Viewport, self).__init__(parent) > self.scene = QGraphicsScene() > self.image = Image() > self.image.setPos(100, 100) > self.scene.addItem(self.image) > self.setScene(self.scene) > self.image.scene = self.scene > self.image.view = self > > def mousePressEvent(self, event): > super(Viewport, self).mousePressEvent(event) > > self.image.mobile = (self.image.mobile + 1) % 2 # Toggle mobility > > x = self.image.x() # + int(self.image.width / 2) > y = self.image.y() # + int(self.image.height / 2) > QCursor.setPos(x, y) > > relative = self.mapFromGlobal(self.image.absolute) > > print "absolute.x() = {0} absolute.y() = {1}"\ > .format(self.image.absolute.x(), self.image.absolute.y()) > > print "relative.x() = {0} relative.y() = {1}"\ > .format(relative.x(), relative.y()) > > > class MainWindow(QWidget): > > def __init__(self, parent=None): > super(MainWindow, self).__init__(parent) > > self.view = Viewport(self) > > hbox = QHBoxLayout() > hbox.addWidget(self.view) > > self.setLayout(hbox) > > > app = QApplication(sys.argv) > window = MainWindow() > window.show() > sys.exit(app.exec_()) > _______________________________________________ > PySide mailing list > PySide at qt-project.org > http://lists.qt-project.org/mailman/listinfo/pyside From dc.loco at gmail.com Tue Aug 9 23:27:16 2016 From: dc.loco at gmail.com (Kevin Cole) Date: Tue, 9 Aug 2016 17:27:16 -0400 Subject: [PySide] SVG image follow mouse w/o drag and drop? In-Reply-To: References: <10039_1470405485_57A49B6C_10039_12_2_CA+pvXRe3Sws-LbX7OpMWZp=a2zzR4AuMFNsV9Zbs34_CN1a5cQ@mail.gmail.com> Message-ID: On Fri, Aug 5, 2016 at 11:13 AM, Purma Jukka wrote: > Hi, > > You don’t have to do anything in QGraphicsView, you can have mousePressEvent in Image to toggle floating on and off. These events get QGraphicsMouseEvents as parameters and these have the information you need about position of cursor or mouse press. So, in short, remove mousePressEvent from viewPort and replace hoverMoveEvent in your Image with this and it will work: > > > def hoverMoveEvent(self, event): > if self.mobile: > print("Moving") > self.setPos(event.scenePos() - QPoint(self.width / 2, self.height / 2)) > > def mousePressEvent(self, event): > self.mobile = not self.mobile # Toggle mobility > super().mousePressEvent(event) > > Jukka > -- Thanks. That worked. I cannot say that I really understand where various methods are supposed to go yet, but you've helped me with my immediate problem. From dc.loco at gmail.com Thu Aug 11 00:38:53 2016 From: dc.loco at gmail.com (Kevin Cole) Date: Wed, 10 Aug 2016 18:38:53 -0400 Subject: [PySide] How do I hide a QGraphicsItem's "focus outline"? Message-ID: When my QGraphicsItem receives a mousePressEvent, it draws a dotted-line rectangle around the item. Is there a way to suppress that? (I want the item selected / focused, but I don't want to see the dotted line. I'm actually working with a QGraphicSvgItem, but I don't think that will make a difference. From chgans at gna.org Thu Aug 11 01:54:25 2016 From: chgans at gna.org (Ch'Gans) Date: Thu, 11 Aug 2016 11:54:25 +1200 Subject: [PySide] How do I hide a QGraphicsItem's "focus outline"? In-Reply-To: References: Message-ID: On 11 August 2016 at 10:38, Kevin Cole wrote: > When my QGraphicsItem receives a mousePressEvent, it draws a > dotted-line rectangle around the item. Is there a way to suppress > that? (I want the item selected / focused, but I don't want to see the > dotted line. > > I'm actually working with a QGraphicSvgItem, but I don't think that > will make a difference. If i understand your problem correctly,you're talking about the QGraphicSvgItem's paint function that draws outline when the item is selected or not. If that's the case, you'll have to implement your own SVG item (or override it), which might not be as complicated as it first looks. But since you're using python, that might not be the way you would be kin to go. My 2 cents, Chris > _______________________________________________ > PySide mailing list > PySide at qt-project.org > http://lists.qt-project.org/mailman/listinfo/pyside From jukka.purma at aalto.fi Thu Aug 11 09:07:16 2016 From: jukka.purma at aalto.fi (Purma Jukka) Date: Thu, 11 Aug 2016 07:07:16 +0000 Subject: [PySide] How do I hide a QGraphicsItem's "focus outline"? In-Reply-To: <9092_1470873274_57ABBEBA_9092_1460_1_CABxGUTjjX4usV6yo1YcKvY7ChKpcWAAbw2N8YsYaVZypc2YPNQ@mail.gmail.com> References: <9092_1470873274_57ABBEBA_9092_1460_1_CABxGUTjjX4usV6yo1YcKvY7ChKpcWAAbw2N8YsYaVZypc2YPNQ@mail.gmail.com> Message-ID: > Ch'Gans kirjoitti 11.8.2016 kello 2.54: > > On 11 August 2016 at 10:38, Kevin Cole wrote: >> When my QGraphicsItem receives a mousePressEvent, it draws a >> dotted-line rectangle around the item. Is there a way to suppress >> that? (I want the item selected / focused, but I don't want to see the >> dotted line. >> >> I'm actually working with a QGraphicSvgItem, but I don't think that >> will make a difference. > > If i understand your problem correctly,you're talking about the > QGraphicSvgItem's paint function that draws outline when the item is > selected or not. > If that's the case, you'll have to implement your own SVG item (or > override it), which might not be as complicated as it first looks. > But since you're using python, that might not be the way you would be kin to go. > > My 2 cents, > Chris > Have you enabled some of these flags? http://doc.qt.io/qt-5/qgraphicsitem.html#GraphicsItemFlag-enum If e.g. ItemIsSelectable is on, QGraphicsSvgItem will try to see if isSelected() is True in paint function, and draw accordingly. If you think you don’t need Qt’s support for selecting graphicsitems, you can a) toggle of that ItemIsSelectable or b) override isSelected -function to return False. Don’t know if paint function relies on this public function, though. If neither works, the easiest way to implement your own SVG item would be to make a new QGraphicsItem subclass that contains QGraphicsSvgItem as a child item. Basically when you create your QGraphicsItem, in it init it creates QGraphicsSvgItem and sets the QGraphicsItem to be its parentItem. QGraphicsItem’s boundingRect and paint should be implemented as empty — the contained object is drawn & included automatically. Parent QGraphicsItem would be the one to capture all mouse events, be selected, set the position on scene etc, child QGraphicsSvgItem would just draw the SVG, untouched by other events. One thing that I forgot to mention in your last example is that you should avoid accidentally overwriting Qt functions when naming class variables, your last example had Image.scene that overrides inherited QGraphicsItem’s scene() -function and can cause odd behaviour along the way. Usually when working with GraphicsItems it is enough to check if nothing in http://doc.qt.io/qt-5/qgraphicsitem.html gets overridden. Jukka > >> _______________________________________________ >> PySide mailing list >> PySide at qt-project.org >> http://lists.qt-project.org/mailman/listinfo/pyside > _______________________________________________ > PySide mailing list > PySide at qt-project.org > http://lists.qt-project.org/mailman/listinfo/pyside From dc.loco at gmail.com Thu Aug 11 15:44:12 2016 From: dc.loco at gmail.com (Kevin Cole) Date: Thu, 11 Aug 2016 09:44:12 -0400 Subject: [PySide] How do I hide a QGraphicsItem's "focus outline"? In-Reply-To: References: <9092_1470873274_57ABBEBA_9092_1460_1_CABxGUTjjX4usV6yo1YcKvY7ChKpcWAAbw2N8YsYaVZypc2YPNQ@mail.gmail.com> Message-ID: Thanks all. Specifically Purma Jukka , whose solution proved simplest to understand. I had thought that I needed to make the item selectable in order to move it. Not so. Removing the code that set that flag fixed everything. From frank at ohufx.com Mon Aug 15 05:14:35 2016 From: frank at ohufx.com (Frank Rueter | OHUfx) Date: Mon, 15 Aug 2016 15:14:35 +1200 Subject: [PySide] QLIstView: how to make click in editor behave the same as click in item Message-ID: Hi all, I have a custom delegate in a QListView and am trying to figure out how to make single click into the editor effect the view's selection model the same way as a click on an item that is not in editing mode. I am currently trying this in the view's mousePressEvent(): def mousePressEvent(self, event): index = self.indexAt(event.pos()) self.selectionModel().select(index, QtGui.QItemSelectionModel.SelectCurrent) super(ElementView, self).mousePressEvent(event) This selects the underlying index but it does not effect the selection according to the view's selectionMode, i.e. it does not extend the existing selection as expected. I thought that's what the QtGui.QItemSelectionModel.SelectCurrent flag was for, but it doesn't seem to work that way. Any ideas? Cheers, frank -- ohufxLogo 50x50 *vfx compositing | *workflow customisation and consulting * * -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: ohufxLogo_50x50.png Type: image/png Size: 2666 bytes Desc: not available URL: From frank at ohufx.com Tue Aug 16 03:04:55 2016 From: frank at ohufx.com (Frank Rueter | OHUfx) Date: Tue, 16 Aug 2016 13:04:55 +1200 Subject: [PySide] but with QListView and drag&drop? Message-ID: <9041a4fd-663c-7141-5688-db7583f57d31@ohufx.com> Hi guys, I just ran into the problem that my custom QListView class wouldn't accept drop events. After a bit of poking I found that the culprit was the QtGui.QListView.IconMode which seemed to reject drop events as a side effect (bug or feature I don't know). So I then proceeded to use setAcceptDrops(True) to explicitly allow drop events, but to no avail. However, and this is what feels like a bug, if I use setAcceptDrops(False) it does accept drop events. Am I misunderstanding the use of this or is this a bug? Some examples: this will accept drop events: view = QtGui.QListView() this will NOT accept drop events (contrary to the docs ): view = QtGui.QListView() view.setViewMode(QtGui.QListView.*IconMode*) this will NOT accept drop events (bug?): view = QtGui.QListView() view.setViewMode(QtGui.QListView.IconMode) view.setAcceptDrops(*True*) this will accept drop events (bug?): view = QtGui.QListView() view.setViewMode(QtGui.QListView.IconMode) view.setAcceptDrops(*False*) I am using PySide 1.2.2 and QT 4.8.7 Cheers, frank -- ohufxLogo 50x50 *vfx compositing | *workflow customisation and consulting * * -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: ohufxLogo_50x50.png Type: image/png Size: 2666 bytes Desc: not available URL: From frank at ohufx.com Tue Aug 16 06:35:01 2016 From: frank at ohufx.com (Frank Rueter | OHUfx) Date: Tue, 16 Aug 2016 16:35:01 +1200 Subject: [PySide] but with QListView and drag&drop? In-Reply-To: <9041a4fd-663c-7141-5688-db7583f57d31@ohufx.com> References: <9041a4fd-663c-7141-5688-db7583f57d31@ohufx.com> Message-ID: Hmm, looks like the issue is only for non-default drag/drop actions, i.e. when I drag a custom widget into a QListView. I have enabled drag/drop in the model etc. but to no avail so far. Need to tinker with this some more... On 16/08/16 1:04 PM, Frank Rueter | OHUfx wrote: > Hi guys, > > I just ran into the problem that my custom QListView class wouldn't > accept drop events. > After a bit of poking I found that the culprit was the > QtGui.QListView.IconMode which seemed to reject drop events as a side > effect (bug or feature I don't know). > So I then proceeded to use setAcceptDrops(True) to explicitly allow > drop events, but to no avail. > > However, and this is what feels like a bug, if I use > setAcceptDrops(False) it does accept drop events. > Am I misunderstanding the use of this or is this a bug? > > Some examples: > > this will accept drop events: > view = QtGui.QListView() > > this will NOT accept drop events (contrary to the docs > ): > > view = QtGui.QListView() > view.setViewMode(QtGui.QListView.*IconMode*) > > this will NOT accept drop events (bug?): > > view = QtGui.QListView() > view.setViewMode(QtGui.QListView.IconMode) > view.setAcceptDrops(*True*) > > this will accept drop events (bug?): > > view = QtGui.QListView() > view.setViewMode(QtGui.QListView.IconMode) > view.setAcceptDrops(*False*) > > I am using PySide 1.2.2 and QT 4.8.7 > > Cheers, > frank > > > -- > ohufxLogo 50x50 *vfx compositing > | *workflow customisation > and consulting * * > > > > _______________________________________________ > PySide mailing list > PySide at qt-project.org > http://lists.qt-project.org/mailman/listinfo/pyside -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: image/png Size: 2666 bytes Desc: not available URL: From frank at ohufx.com Tue Aug 16 09:26:34 2016 From: frank at ohufx.com (Frank Rueter | OHUfx) Date: Tue, 16 Aug 2016 19:26:34 +1200 Subject: [PySide] QListView: drag&drop custom item Message-ID: <0c9ef571-4c98-a901-c158-f06f02865634@ohufx.com> Hi, I am trying to get drag&drop to work between two QListViews using a custom item. I can't find the info I need online other than this document which helped a little bit but now I'm stuck. Drag&drop from one QListView to another works fine when I use a QStandardItem to hold my data, but when I use a custom item I run into trouble, because the receiving model/view creates a QStandardItem when the incoming custom items are dropped. Ideally I could tell the receiving model to use my custom item as the default item and otherwise just do it's thing, but I suppose it won't be that easy?! I have played around with the receiving model's dropMimeData() and insertRows() methods but can't work out how to read the incoming data to then insert a custom item into the receiving model manually. In QAbstractItemModel.dropMimeData() I tried reading mimeData.data('application/x-qabstractitemmodeldatalist'), but that returns a byte stream that I don't know how to handle. Do I have to re-implement the sender's drag data as well to send the custom item in the first place? It seems that everything works out of the box except the creation of the QStandardItem upon drop, rather than my custom item, so I am hoping I don't have to re-invent the (drag&drop) wheel just to get that one part right?! Any advise would be greatly appreciated. Thanks, frank -- ohufxLogo 50x50 *vfx compositing | *workflow customisation and consulting * * -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: ohufxLogo_50x50.png Type: image/png Size: 2666 bytes Desc: not available URL: From oislone at ois.idv.tw Wed Aug 17 12:20:55 2016 From: oislone at ois.idv.tw (oislone) Date: Wed, 17 Aug 2016 18:20:55 +0800 Subject: [PySide] self.SelectionMode() return Message-ID: <49910e05-35da-0601-8565-f582873b29e2@ois.idv.tw> hello all: i use Arch Linux Python 3.5 PySide 1.2.4-3 write code : ----------------------------------------- self.setSelectionMode(QAbstractItemView.MultiSelection) print(self.SelectionMode()) -------------------------------------------- return PySide.QtGui.QAbstractItemView.SelectionMode.NoSelection but i cau use self.selectAll()self.clearSelection() why ? -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Wed Aug 17 18:17:02 2016 From: timr at probo.com (Tim Roberts) Date: Wed, 17 Aug 2016 09:17:02 -0700 Subject: [PySide] self.SelectionMode() return In-Reply-To: <49910e05-35da-0601-8565-f582873b29e2@ois.idv.tw> References: <49910e05-35da-0601-8565-f582873b29e2@ois.idv.tw> Message-ID: <4e0aacb5-9acc-69e8-1c57-097396e6e929@probo.com> oislone wrote: > > write code : > ----------------------------------------- > self.setSelectionMode(QAbstractItemView.MultiSelection) > print(self.SelectionMode()) > -------------------------------------------- > return PySide.QtGui.QAbstractItemView.SelectionMode.NoSelection > > but i cau use self.selectAll() self.clearSelection()why ? The SelectionMode controls the user interface. That is, it determines what kind of selection the user is able to do from the keyboard and mouse. It's not trying to protect you from yourself. If you don't want to select items, then don't call selectAll or clearSelection. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. -------------- next part -------------- An HTML attachment was scrubbed... URL: From oislone at ois.idv.tw Wed Aug 17 18:44:18 2016 From: oislone at ois.idv.tw (oislone) Date: Thu, 18 Aug 2016 00:44:18 +0800 Subject: [PySide] self.SelectionMode() return Message-ID: <1f3e00e4-1dc1-0970-ba15-f3acb87e8f41@ois.idv.tw> Tim Roberts. thank Sorry . i problem is self.setSelectionMode(QAbstractItemView.MultiSelection) x = self.SelectionMode() x is QAbstractItemView.SelectionMode.NoSelection why x not is QAbstractItemView.SelectionMode.MultiSelection i wnat check current SelectionMode() -------------- next part -------------- An HTML attachment was scrubbed... URL: From frank at ohufx.com Thu Aug 18 01:45:20 2016 From: frank at ohufx.com (Frank Rueter | OHUfx) Date: Thu, 18 Aug 2016 11:45:20 +1200 Subject: [PySide] self.SelectionMode() return In-Reply-To: <1f3e00e4-1dc1-0970-ba15-f3acb87e8f41@ois.idv.tw> References: <1f3e00e4-1dc1-0970-ba15-f3acb87e8f41@ois.idv.tw> Message-ID: try self.selectionMode() rather than try self.SelectionMode() I.e. use a lower case "s". On 18/08/16 4:44 AM, oislone wrote: > Tim Roberts. thank > Sorry . i problem is > > self.setSelectionMode(QAbstractItemView.MultiSelection) > x = self.SelectionMode() > x is QAbstractItemView.SelectionMode.NoSelection > why x not is QAbstractItemView.SelectionMode.MultiSelection > > i wnat check current SelectionMode() > > > > _______________________________________________ > PySide mailing list > PySide at qt-project.org > http://lists.qt-project.org/mailman/listinfo/pyside -------------- next part -------------- An HTML attachment was scrubbed... URL: From oislone at ois.idv.tw Thu Aug 18 06:53:11 2016 From: oislone at ois.idv.tw (oislone) Date: Thu, 18 Aug 2016 12:53:11 +0800 Subject: [PySide] self.SelectionMode() return In-Reply-To: <57B49C84.9040309@gmail.com> References: <1f3e00e4-1dc1-0970-ba15-f3acb87e8f41@ois.idv.tw> <57B49C84.9040309@gmail.com> Message-ID: <8ee7f703-2159-c6c7-0082-984360248212@ois.idv.tw> > SelectionMode is an enum. You are constructing a new instance of that > enum with the default value (0), which corresponds to NoSelection. There > is no "current SelectionMode", because SelectionMode *is a type*. > > What you *want* to do is query the selectionMode of your item view. Note > the lowercase initial 's'. > > In general, methods *always start with a lower case letter* (in Qt and > PySide, anyway). Types start with upper case letters. > Yse. I am a fool. change to selectionMode() is right return. i use too much IDE Auto completion. THANK YOU. From frank at ohufx.com Thu Aug 18 09:25:45 2016 From: frank at ohufx.com (Frank Rueter | OHUfx) Date: Thu, 18 Aug 2016 19:25:45 +1200 Subject: [PySide] self.SelectionMode() return In-Reply-To: <8ee7f703-2159-c6c7-0082-984360248212@ois.idv.tw> References: <1f3e00e4-1dc1-0970-ba15-f3acb87e8f41@ois.idv.tw> <57B49C84.9040309@gmail.com> <8ee7f703-2159-c6c7-0082-984360248212@ois.idv.tw> Message-ID: <40edd41d-e7d0-631d-c863-2e19133d29a3@ohufx.com> Same here. My IDE auto completed to upper case as well. Never had that with anything else, so I don't think it's the IDE's fault. On 18/08/16 4:53 PM, oislone wrote: > > >> SelectionMode is an enum. You are constructing a new instance of that >> enum with the default value (0), which corresponds to NoSelection. There >> is no "current SelectionMode", because SelectionMode *is a type*. >> >> What you *want* to do is query the selectionMode of your item view. Note >> the lowercase initial 's'. >> >> In general, methods *always start with a lower case letter* (in Qt and >> PySide, anyway). Types start with upper case letters. >> > > Yse. I am a fool. change to selectionMode() is right return. > i use too much IDE Auto completion. > THANK YOU. > > _______________________________________________ > PySide mailing list > PySide at qt-project.org > http://lists.qt-project.org/mailman/listinfo/pyside From frank at ohufx.com Sat Aug 27 07:23:07 2016 From: frank at ohufx.com (Frank Rueter | OHUfx) Date: Sat, 27 Aug 2016 17:23:07 +1200 Subject: [PySide] model/view: using fetchmore with scroll bar and filter proxy Message-ID: <501dd321-cff8-bcd0-1b03-3340e1b65633@ohufx.com> Hi all, I'm implementing a model using fetchMore, to retrieve data from a model on demand, which in my case means the model fetches more data as the user scrolls down a QListView. Technically this works just fine, except that the scrollbar adjusts it's width every time it hits the bottom, to accommodate the increase in rowCount. I suppose I need to re-implement some methods to take over control of the view's verticalScrollbar(), but I'm not quite sure how. I suspect I should use the view's resizeEvent to set a static range for my scrollbar, but I also need to make it stop adjust itself every time fetchMore is called by the model. Has anybody ever done this? Also, is anybody aware of examples that show the use of a QAbstractListModel (or QAbstractItemModel in general) which deploys the fetchMore logic along a QSortFilterProxyModdel? Currently my filter results are quite unexpected after implementing fetchMore and I'm not quite sure where to start to fix this. Any pointers would be much appreciated. Cheers, frank -- ohufxLogo 50x50 *vfx compositing | *workflow customisation and consulting * * -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: ohufxLogo_50x50.png Type: image/png Size: 2666 bytes Desc: not available URL: From frank at ohufx.com Tue Aug 30 22:35:22 2016 From: frank at ohufx.com (Frank Rueter | OHUfx) Date: Wed, 31 Aug 2016 08:35:22 +1200 Subject: [PySide] model/view: using fetchmore with scroll bar and filter proxy Message-ID: <0pkgo6tqiri3x886ad25lqtr.1472589322232@email.android.com> Anybody? -------- Original message -------- From: Frank Rueter | OHUfx Date: 27/08/2016 5:23 PM (GMT+12:00) To: pyside at qt-project.org Subject: [PySide] model/view: using fetchmore with scroll bar and filter proxy Hi all, I'm implementing a model using fetchMore, to retrieve data from a model on demand, which in my case means the model fetches more data as the user scrolls down a QListView. Technically this works just fine, except that the scrollbar adjusts it's width every time it hits the bottom, to accommodate the increase in rowCount. I suppose I need to re-implement some methods to take over control of the view's verticalScrollbar(), but I'm not quite sure how. I suspect I should use the view's resizeEvent to set a static range for my scrollbar, but I also need to make it stop adjust itself every time fetchMore is called by the model. Has anybody ever done this? Also, is anybody aware of examples that show the use of a QAbstractListModel (or QAbstractItemModel in general) which deploys the fetchMore logic along a QSortFilterProxyModdel? Currently my filter results are quite unexpected after implementing fetchMore and I'm not quite sure where to start to fix this. Any pointers would be much appreciated. Cheers, frank -- vfx compositing | workflow customisation and consulting -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: ohufxLogo_50x50.png Type: image/png Size: 2666 bytes Desc: not available URL: