#pyqt | Logs for 2019-02-20

Back
[03:02:27] -!- n1` has joined #pyqt
[03:52:26] -!- BPL has joined #pyqt
[05:00:28] -!- thebigj has parted #pyqt
[06:28:54] -!- swalladge has quit [Read error: Connection reset by peer]
[06:29:34] -!- swalladge has joined #pyqt
[08:29:01] -!- TechSmurf has quit [Ping timeout: 250 seconds]
[08:44:04] -!- Siecje has joined #pyqt
[10:44:34] -!- plasma_ has quit [Remote host closed the connection]
[11:07:30] -!- BPL has quit [Quit: Leaving]
[11:51:47] -!- Afrix has joined #pyqt
[13:37:52] -!- ncl has parted #pyqt
[16:43:16] -!- storgance has joined #pyqt
[17:05:22] -!- Siecje has quit [Quit: Leaving.]
[17:09:00] <storgance> Hello, everyone. I am fairly new to model/view programming, but I am attempting to learn it. I am attempting to translate a C++ example I found on the internet into my own application using a custom delegate with roles. However, I am getting an error which I think is the cause of some internal call in the PyQt after calling paint() on a QStyledItemDelegate. I have the tutorial, my source code (with important lines commented), and t
[17:09:03] <storgance> https://pastebin.com
[17:09:36] <altendky> storgance: you made it back :] now, can i find that thing i made up for you...
[17:09:54] <storgance> Oh, hello!
[17:10:08] <altendky> https://gist.github.com
[17:10:45] <storgance> Woah
[17:11:07] <altendky> storgance: just a quick overview. we were talking about the custom widgets in a list view and delegates. so WidgetDelegate would be the generic sort of library class and then you can make whatever you want instead of DisplayWidget.
[17:11:26] <altendky> just in case it's at all relevant :]
[17:12:41] <Avaris> storgance: for your error, you should use `super().paint(...)` instead
[17:12:44] <altendky> you have to provide the WidgetDelegate instance with some callable (in this case DisplayWidget.fill_from_index, but you could name it whatever) so it can get the proper info in
[17:12:57] <altendky> (and in the meantime, Avaris actually bothered with your present question...)
[17:12:59] <storgance> Oh woah, this does look useful
[17:13:32] <storgance> Ohh okay. Thank you both!
[17:13:55] <Avaris> storgance: and as a side, in cases where you have to do `QStyledItemDelegate.paint` (which is very rarely) you also have to pass `self` as well
[17:14:37] <altendky> but mostly, use super()
[17:15:12] -!- TechSmurf has joined #pyqt
[17:15:16] <altendky> storgance: Avaris and i discussed what i did vs. just a pure custom delegate and paint method like you have. we've got different tendencies there. *shrug* obviously both can work well.
[17:16:04] <Avaris> and you might want to check qfontmetrics, so you don't have to assume some dimensions about your text
[17:16:06] <storgance> Avaris: Doing super().paint(painter, option, index) appears to cause an infinite recursion case somehow? Did I misunderstand what you meant?
[17:16:34] <storgance> Avaris: You're correct about that, I excluded that part from my code just for now.
[17:17:08] <storgance> altendky: What kind of advantages does each way have? or is it just identical in the end?
[17:17:11] <altendky> (that's why i like my way :] just let regular widgets figure all that out, albeit probably with a bit of overhead)
[17:18:12] <altendky> storgance: with a custom paint you decide how to paint what where (hopefully remembering to address scaling and margins and so on). by letting a 'real widget' paint stuff, you get whatever normal widgets would do in that scenario.
[17:18:43] <altendky> Avaris: did we conclude something like 'for a little text, it shouldn't be that hard to paint. for any sort of complex layouts... use a widget'?
[17:18:43] <storgance> What do you mean by address scaling?
[17:19:06] <altendky> storgance: high dpi displays and getting your test size right which may depend on which monitor you are on etc
[17:19:11] <altendky> *text size
[17:19:31] <storgance> Ohh, pfffu. I should probably just emulate your way then. Thank you for all your help!
[17:19:35] <Avaris> altendky: something like that
[17:20:06] <altendky> storgance: i avoid learning about how to do that stuff right when i can. maybe it really isn't all that hard :]
[17:20:20] <Avaris> hmm, recursion is odd...
[17:20:36] <altendky> shouldn't the inheritance be to QStyledItemDelegate? not sure how that would relate, but maybe
[17:21:27] <storgance> I'm not sure, that's just how they did it in the tutorial. Typical weird tutorials
[17:24:45] <altendky> storgance: side note, my example didn't actually successfully set the button colors on windows. they did get set in linux. (and a button was a bad choice, this doesn't make an interactive widget, just a snapshot of it sitting there)
[17:25:08] <storgance> Oh, strange...
[17:25:35] <altendky> meh, something about styling and buttons and the os drawing them i think. so, qt doesn't get to set the color like that
[17:25:38] -!- Avaris has quit [Ping timeout: 268 seconds]
[17:25:46] <altendky> setting the text color instead worked
[17:26:30] -!- Avaris has joined #pyqt
[17:28:22] <Avaris> storgance: btw, you shouldn't use standard roles for your own stuff: https://doc.qt.io
[17:28:41] <Avaris> custom roles goes to 32+
[17:29:22] <altendky> i made myself a UserRole enumeration starting at the UserRole number so i could have names for them. i should probably add the standard ones to that enum really i guess to have one place i go
[17:30:23] <Avaris> wait 0x0100 isn't 32... did it change?
[17:30:43] <altendky> i never thought it was 32, but i've only been using it for a couple years
[17:30:59] <Avaris> i could swear in qt4 it was 32 :)
[17:31:01] <altendky> and there's QtCore.Qt.UserRoles instead of knowing :]
[17:31:13] <altendky> storgance: did changing to QStyledItemDelegate make any difference on the recursion? though i think there are notes about recursion hazards with paint()
[17:31:45] <Avaris> yeah it is :) https://doc.qt.io
[17:31:55] <storgance> Avaris: O-oh, I didn't know that was a thing. I saw both the enum in the tutorial and the roles in the mvp page, but I guess I never thought to look for the enum in the documentation
[17:32:41] <storgance> Avaris: hex 20 is 32 I believe, unless I'm missing something
[17:33:24] <altendky> storgance: qt5 is 0x0100. but don't use that, use QtCore.Qt.UserRole and then increment from there
[17:33:39] <Avaris> ^ +
[17:37:20] <storgance> Ohh, I see
[17:37:40] <Avaris> ok so... qabstractitemdelegate.paint is pure virtual and calling it calls the actual_class.paint again? weird
[17:37:59] <altendky> that's a fun result
[17:42:01] <Avaris> i guess it makes sense
[17:43:28] <storgance> when you say actual_class, is that implying something along the lines of that Python knows which class called a function, and for some reason abstract classes call the calling classes method?
[17:43:51] <Avaris> actual_class == your subclass
[17:45:12] <storgance> I see. So...all abstract superclasses
[17:45:15] <storgance> typo
[17:45:57] <altendky> it's the particular method that's pure virtual
[17:45:58] <storgance> So, all abstract superclasses' methods call the calling subclass' method if called? Wouldn't that always cause infinite recursion?
[17:46:20] <Avaris> no, the pure virtual ones do
[17:46:52] <storgance> What exactly do you mean by pure virtual? Ones that are "prototyped" in some way?
[17:47:06] <Avaris> do you know c++?
[17:47:24] <storgance> only enough to do rudimentary stuff like a calculator
[17:48:37] <storgance> Oh, so it's just exactly what I would expect from C, stuff defined in a header that is redefined later.
[17:48:48] <Avaris> ok crash course: see all these `virtual this` in methods? https://doc.qt.io
[17:49:03] <storgance> Yes
[17:50:46] <Avaris> they make methods 'virtual', meaning: you subclass it and override virtual method (say A). but some other method (say B) that you didn't override calls A. then B will call *your* A
[17:51:17] <Avaris> without virtual it won't work like that. B would call BaseClass.A
[17:51:29] <storgance> Ohh, I see, thank you.
[17:52:33] <Avaris> "pure virtual" is virtual but with no implementation at all. nothing to call there. so it goes to YourClass.whatever (I think... my c++ knowledge starts to get a little fuzzy around there :) )
[17:52:51] <altendky> well, wouldn't c++ just not compile?
[17:52:58] <storgance> Perhaps...
[17:53:03] <altendky> if you tried to call a pure virtual
[17:53:09] <altendky> or, if you hadn't implemented it yourself
[17:53:36] <Avaris> it might be in the "undefined" territory
[17:54:34] <storgance> you have entered: the compiler behavior zone
[17:55:03] <storgance> I have to go, I should be back at some point in a bit. Thank you both for everything!
[17:55:15] -!- storgance has quit [Quit: Page closed]
[17:57:10] -!- mintograde has joined #pyqt
[18:15:44] -!- minto has joined #pyqt
[18:16:50] -!- mintograde has quit [Ping timeout: 255 seconds]
[18:45:33] -!- kushal has quit [Ping timeout: 256 seconds]
[18:48:53] -!- kushal has joined #pyqt
[19:40:32] -!- Avaris has quit [Ping timeout: 255 seconds]
[19:41:53] -!- Avaris has joined #pyqt
[21:26:38] -!- stochastix has quit [Quit: http://quassel-irc.org - Chat comfortably. Anywhere.]
[22:01:24] -!- lee_76 has joined #pyqt
[23:53:28] -!- Afrix has quit [Quit: Leaving]