07-30-2014, 07:55 AM | #1 |
Grand Sorcerer
Posts: 6,171
Karma: 16228536
Join Date: Sep 2009
Location: UK
Device: Kobo: KA1, ClaraHD, Forma, Libra2, Clara2E. PocketBook: TouchHD3
|
Simple PyQt help, please
I'm trying to tidy up the widget creating/layout code in a rather large QDialog which contains many QGroupBox widgets each of which contains a list of buttons. For each groupbox the buttons will all be QPushButton or all QCheckBox.
|
07-30-2014, 08:11 AM | #2 |
creator of calibre
Posts: 43,776
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Pass in the actual classes rather than strings, like this
Code:
def create_groupbox(self, lvalues, widget=QPushButton): button = widget() Code:
if isinstance(button, QPushButton): # is a QPushButton elif isinstance(button, QCheckBox): # is a check box |
Advert | |
|
07-30-2014, 08:28 AM | #3 | ||
Grand Sorcerer
Posts: 11,703
Karma: 6658935
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Code:
if isinstance(self.blist[0], QPushButton): Last edited by chaley; 07-30-2014 at 08:30 AM. |
||
07-30-2014, 08:31 AM | #4 |
Grand Sorcerer
Posts: 6,171
Karma: 16228536
Join Date: Sep 2009
Location: UK
Device: Kobo: KA1, ClaraHD, Forma, Libra2, Clara2E. PocketBook: TouchHD3
|
Thank you! Simple once you know
|
08-16-2014, 10:38 AM | #5 |
Junior Member
Posts: 1
Karma: 10
Join Date: Aug 2014
Device: Kindle 4
|
|
Advert | |
|
08-16-2014, 11:05 AM | #6 |
creator of calibre
Posts: 43,776
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Avoid eval(), it is a security risk, while in this case it is probably harmless, if you want a one-liner, do this, instead:
from PyQt5 import Qt as QtGui button = getattr(QtGui, widget)() |
Thread Tools | Search this Thread |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
PyQt help re: QWebView widget, please | jackie_w | Development | 2 | 10-28-2013 10:00 AM |
Trio of Picture Books - Simple Animals, Simple Shapes, and You're My Baby! | Manley Peterson | Self-Promotions by Authors and Publishers | 5 | 01-06-2012 08:55 PM |
erm, simple question , hope for simple answer! | al zymers | Amazon Kindle | 5 | 09-25-2010 01:01 PM |
Simple question for a simple mind :) | PKFFW | OpenInkpot | 6 | 08-27-2009 09:00 PM |
PyQT warning... | alexxxm | Calibre | 1 | 07-28-2008 04:18 AM |