implement custom Q(Double)SpinBox widget for onFocus selection

This commit is contained in:
Roland W-H 2025-02-11 21:19:05 +00:00
parent 9ef6048601
commit 68ac992483
3 changed files with 37 additions and 22 deletions

View File

@ -71,7 +71,7 @@
</widget> </widget>
</item> </item>
<item row="5" column="2"> <item row="5" column="2">
<widget class="QDoubleSpinBox" name="share_plat_max_fee_box"> <widget class="FastEditQDoubleSpinBox" name="share_plat_max_fee_box">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
@ -97,7 +97,7 @@
</widget> </widget>
</item> </item>
<item row="6" column="2"> <item row="6" column="2">
<widget class="QDoubleSpinBox" name="share_deal_fee_box"> <widget class="FastEditQDoubleSpinBox" name="share_deal_fee_box">
<property name="buttonSymbols"> <property name="buttonSymbols">
<enum>QAbstractSpinBox::ButtonSymbols::NoButtons</enum> <enum>QAbstractSpinBox::ButtonSymbols::NoButtons</enum>
</property> </property>
@ -122,12 +122,12 @@
<item row="5" column="0" colspan="2"> <item row="5" column="0" colspan="2">
<widget class="QLabel" name="share_plat_max_fee_lab"> <widget class="QLabel" name="share_plat_max_fee_lab">
<property name="text"> <property name="text">
<string>Share platform fee cap/mth</string> <string>Share platform monthly fee cap</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="2"> <item row="2" column="2">
<widget class="QDoubleSpinBox" name="fund_deal_fee_box"> <widget class="FastEditQDoubleSpinBox" name="fund_deal_fee_box">
<property name="buttonSymbols"> <property name="buttonSymbols">
<enum>QAbstractSpinBox::ButtonSymbols::NoButtons</enum> <enum>QAbstractSpinBox::ButtonSymbols::NoButtons</enum>
</property> </property>
@ -147,7 +147,7 @@
</widget> </widget>
</item> </item>
<item row="8" column="2"> <item row="8" column="2">
<widget class="QSpinBox" name="share_deal_reduce_trades_box"> <widget class="FastEditQSpinBox" name="share_deal_reduce_trades_box">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
@ -200,7 +200,7 @@
</widget> </widget>
</item> </item>
<item row="4" column="2"> <item row="4" column="2">
<widget class="QDoubleSpinBox" name="share_plat_fee_box"> <widget class="FastEditQDoubleSpinBox" name="share_plat_fee_box">
<property name="buttonSymbols"> <property name="buttonSymbols">
<enum>QAbstractSpinBox::ButtonSymbols::NoButtons</enum> <enum>QAbstractSpinBox::ButtonSymbols::NoButtons</enum>
</property> </property>
@ -220,7 +220,7 @@
</widget> </widget>
</item> </item>
<item row="9" column="2"> <item row="9" column="2">
<widget class="QDoubleSpinBox" name="share_deal_reduce_amount_box"> <widget class="FastEditQDoubleSpinBox" name="share_deal_reduce_amount_box">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
@ -283,6 +283,18 @@
</property> </property>
</widget> </widget>
</widget> </widget>
<customwidgets>
<customwidget>
<class>FastEditQDoubleSpinBox</class>
<extends>QDoubleSpinBox</extends>
<header>widgets/fastedit_spinbox</header>
</customwidget>
<customwidget>
<class>FastEditQSpinBox</class>
<extends>QSpinBox</extends>
<header>widgets/fastedit_spinbox</header>
</customwidget>
</customwidgets>
<tabstops> <tabstops>
<tabstop>plat_name_box</tabstop> <tabstop>plat_name_box</tabstop>
<tabstop>fund_deal_fee_box</tabstop> <tabstop>fund_deal_fee_box</tabstop>

View File

@ -1,6 +1,6 @@
from PyQt6.QtCore import QRegularExpression, QEvent, QObject, QTimer from PyQt6.QtCore import QRegularExpression, QEvent, QObject, QTimer
from PyQt6.QtGui import QRegularExpressionValidator from PyQt6.QtGui import QRegularExpressionValidator
from PyQt6.QtWidgets import QWidget from PyQt6.QtWidgets import QWidget, QDoubleSpinBox
from PyQt6 import uic from PyQt6 import uic
import main_window import main_window
@ -79,17 +79,6 @@ class PlatformEdit(QWidget):
# NOTE: Signal defined in UI file to close window when save button clicked # NOTE: Signal defined in UI file to close window when save button clicked
self.save_but.clicked.connect(self.init_variables) self.save_but.clicked.connect(self.init_variables)
# Install event filter on input boxes in order to select all text on focus
# TODO: Seems like my eventFilter() override is capturing all events - need to stop this
"""
self.fund_deal_fee_box.installEventFilter(self)
self.share_plat_fee_box.installEventFilter(self)
self.share_plat_max_fee_box.installEventFilter(self)
self.share_deal_fee_box.installEventFilter(self)
self.share_deal_reduce_trades_box.installEventFilter(self)
self.share_deal_reduce_amount_box.installEventFilter(self)
"""
# Set validators # Set validators
# Regex accepts any characters that match [a-Z], [0-9] or _ # Regex accepts any characters that match [a-Z], [0-9] or _
self.plat_name_box.setValidator( self.plat_name_box.setValidator(
@ -120,11 +109,12 @@ class PlatformEdit(QWidget):
self.main_win.show() self.main_win.show()
# When focus is given to an input box, select all text in it (easier to edit) # When focus is given to an input box, select all text in it (easier to edit)
def eventFilter(self, obj: QObject, event: QEvent): def focusInEvent(self, event):
if event.type() == QEvent.Type.FocusIn: print("yay")
if event.gotFocus():
# Alternative condition for % suffix - currently unused # Alternative condition for % suffix - currently unused
#if obj.value() == 0 or obj == self.share_plat_fee_box: #if obj.value() == 0 or obj == self.share_plat_fee_box:
QTimer.singleShot(0, obj.selectAll) QTimer.singleShot(0, sender.selectAll)
return False return False
# This method does multiple things in order to validate the user's inputs: # This method does multiple things in order to validate the user's inputs:

View File

@ -0,0 +1,13 @@
from PyQt6.QtCore import QTimer
from PyQt6.QtWidgets import QSpinBox, QDoubleSpinBox
class FastEditQDoubleSpinBox(QDoubleSpinBox):
def focusInEvent(self, e):
QTimer.singleShot(0, self.selectAll)
super(FastEditQDoubleSpinBox, self).focusInEvent(e)
class FastEditQSpinBox(QSpinBox):
def focusInEvent(self, e):
QTimer.singleShot(0, self.selectAll)
super(FastEditQSpinBox, self).focusInEvent(e)