subclassing

Properly handling a keyPressEvent in a Subclassed PyQT LineEdit

一曲冷凌霜 提交于 2019-12-23 15:12:03
问题 So I have a QLineEdit that I want to catch a shift keypress in. Here's my code: class NoteText(QtGui.QLineEdit): def __init__(self, parent): super (NoteText, self).__init__(parent) def keyPressEvent(self, event): if (event.modifiers() & QtCore.Qt.ShiftModifier): self.shift = True print 'Shift!' As you can guess, I can catch the shift keypress, but then you cannot input text into the LineEdit. I've tried catching keypresses, but I'm not sure quite what to do with them to allow the user to

Non-testable base class extending PHPUnit_Framework_TestCase

馋奶兔 提交于 2019-12-22 01:23:48
问题 Summary How can I create a base class that extends PHPUnit_Framework_TestCase and use that for subclassing actual test cases, without having the base class itself tested by PHPUnit? Further explanation I have a series of related test cases for which I have created a base class that contains some common tests to be inherited by all test cases: BaseClass_TestCase.php: class BaseClass_TestCase extends PHPUnit_Framework_TestCase { function test_common() { // Test that should be run for all

overloaded __iter__ is bypassed when deriving from dict

◇◆丶佛笑我妖孽 提交于 2019-12-21 20:59:37
问题 Trying to create a custom case-insensitive dictionary, I came the following inconvenient and (from my point-of-view) unexpected behaviour. If deriving a class from dict , the overloaded __iter__ , keys , values functions are ignored when converting back to dict . I have condensed it to the following test case: import collections class Dict(dict): def __init__(self): super(Dict, self).__init__(x = 1) def __getitem__(self, key): return 2 def values(self): return 3 def __iter__(self): yield 'y'

Delphi: How to remove subclasses in reverse order?

血红的双手。 提交于 2019-12-21 17:56:28
问题 Mike Lischke's TThemeServices subclasses Application.Handle , so that it can receive broadcast notifications from Windows (i.e. WM_THEMECHANGED ) when theming changes. It subclasses the Application object's window: FWindowHandle := Application.Handle; if FWindowHandle <> 0 then begin // If a window handle is given then subclass the window to get notified about theme changes. {$ifdef COMPILER_6_UP} FObjectInstance := Classes.MakeObjectInstance(WindowProc); {$else} FObjectInstance :=

How to subclass custom UIViewController in Swift?

試著忘記壹切 提交于 2019-12-21 09:03:37
问题 I'd like to create a reusable view controller UsersViewControllerBase . UsersViewControllerBase extends UIViewController , and implements two delegates ( UITableViewDelegate , UITableViewDataSource ), and has two views ( UITableView , UISegmentedControl ) The goal is to inherit the implementation of the UsersViewControllerBase and customise the segmented items of segmented control in UsersViewController class. class UsersViewControllerBase: UIViewController, UITableViewDelegate,

Best practice, overriding __construct() versus providing init() method

[亡魂溺海] 提交于 2019-12-21 06:48:07
问题 When you are subclassing objects and want to extend the initialization code, there are two approaches. Overriding __construct(), and implementing an initialization method that your superclass constructor calls. Method 1: class foo { public function __construct ($arg1, $arg2, $arg3) { // Do initialization } } class bar extends foo { public function __construct ($arg1, $arg2, $arg3) { parent::__construct ($arg1, $arg2, $arg3); // Do subclass initialization } } Method 2 class foo { public

How to subclass a specific jqueryui widget method?

白昼怎懂夜的黑 提交于 2019-12-21 05:52:30
问题 Since I updated jQueryUI to 1.8 I found a couple of issues in our implementations and I could fix it myself without waiting for a fix on their end if I could find out how to subclass a specific method of the datepicker widget so I call the parent code and then execute my code. I was reading on $.widget but I just can't wrap my head around how that is suppose to work. I tried something like this: $.widget("ui.datepicker", { _showDatepicker: function(input) { alert('Yo'); $.datepicker.prototype

Subclassing UINavigationBar … how do I use it in UINavigationController?

两盒软妹~` 提交于 2019-12-20 12:48:10
问题 I wanted to subclass UINavigationBar (to set a custom background image & text color) and use that for all the navigation bars in my app. Looking at the API docs for UINavigationController, it looks like navigationBar is read-only: @property(nonatomic, readonly) UINavigationBar *navigationBar Is there a way to actually use a custom UINavigationBar in my UIViewControllers? I know that other apps have done custom navigation bars, like flickr: http://img.skitch.com/20100520

Performance issues when painting text on custom item delegates in Qt C++

最后都变了- 提交于 2019-12-20 04:24:40
问题 Goal: Creating an item delegate with custom textual content to be used in QListView. Problem: Drawing text with QPainter in a reimplementation of the paint() method of a QAbstractItemDelegate's subclass is noticably slower than drawing shapes and pixmaps. Changing the base class to QStyledItemDelegate does not improve the speed. Setup: Qt 5.9.1, MSVC 2017, tested on Windows 7/10 Pre-research: A similar bug is reported here, however in this particular case the performance issue exists even if

Why can't I have an enum as the underlying type of another enum?

╄→尐↘猪︶ㄣ 提交于 2019-12-20 02:54:38
问题 Why isn't this valid C++?: enum foo : unsigned { first_foo, second_foo }; enum bar : foo { best_foo = first_foo }; GCC 5.4.0 says: /tmp/a.cpp:3:16: error: underlying type ‘foo’ of ‘bar’ must be an integral type enum bar : foo { best_foo = first_foo }; I can understand why I would get this error if foo were a float , or some struct, or what-not. But this seems perfectly legit to me in terms of semantics, type safety etc. What am I missing? 回答1: When you add things to C++, you tend to add the