Put connection details in connection button menu

This commit is contained in:
atse 2023-07-26 16:43:24 +08:00
parent a1a94a9c99
commit ca7c64c115
3 changed files with 23 additions and 10 deletions

View File

@ -197,8 +197,8 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
def _set_up_context_menu(self):
_translate = QtCore.QCoreApplication.translate
self.menu = QtWidgets.QMenu()
self.menu.setTitle('Thermostat settings')
self.connection_menu = QtWidgets.QMenu()
self.connection_menu.setTitle('Connection Settings')
self.ip_set_line = QtWidgets.QLineEdit()
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Fixed, QtWidgets.QSizePolicy.Policy.Expanding)
@ -215,10 +215,10 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
self.ip_set_line.setText(_translate("MainWindow", "192.168.1.26"))
self.ip_set_line.setPlaceholderText(_translate("MainWindow", "IP:port for the Thermostat"))
host = QtWidgets.QWidgetAction(self.menu)
host = QtWidgets.QWidgetAction(self.connection_menu)
host.setDefaultWidget(self.ip_set_line)
self.menu.addAction(host)
self.menu.host = host
self.connection_menu.addAction(host)
self.connection_menu.host = host
self.port_set_spin = QtWidgets.QSpinBox()
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Fixed, QtWidgets.QSizePolicy.Policy.Fixed)
@ -232,10 +232,15 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
self.port_set_spin.setProperty("value", 23)
self.port_set_spin.setObjectName("port_set_spin")
port = QtWidgets.QWidgetAction(self.menu)
port = QtWidgets.QWidgetAction(self.connection_menu)
port.setDefaultWidget(self.port_set_spin)
self.menu.addAction(port)
self.menu.port = port
self.connection_menu.addAction(port)
self.connection_menu.port = port
self.connect_btn.setMenu(self.connection_menu)
self.menu = QtWidgets.QMenu()
self.menu.setTitle('Thermostat settings')
self.fan_group = QtWidgets.QWidget()
self.fan_group.setEnabled(False)

View File

@ -179,7 +179,7 @@
<item>
<layout class="QHBoxLayout" name="settings_layout">
<item>
<widget class="QPushButton" name="connect_btn">
<widget class="QToolButton" name="connect_btn">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
<horstretch>0</horstretch>
@ -207,6 +207,12 @@
<property name="text">
<string>Connect</string>
</property>
<property name="popupMode">
<enum>QToolButton::MenuButtonPopup</enum>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonFollowStyle</enum>
</property>
</widget>
</item>
<item>

View File

@ -92,7 +92,7 @@ class Ui_MainWindow(object):
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.settings_layout = QtWidgets.QHBoxLayout()
self.settings_layout.setObjectName("settings_layout")
self.connect_btn = QtWidgets.QPushButton(parent=self.bottom_settings_group)
self.connect_btn = QtWidgets.QToolButton(parent=self.bottom_settings_group)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Fixed, QtWidgets.QSizePolicy.Policy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
@ -101,6 +101,8 @@ class Ui_MainWindow(object):
self.connect_btn.setMinimumSize(QtCore.QSize(100, 0))
self.connect_btn.setMaximumSize(QtCore.QSize(100, 16777215))
self.connect_btn.setBaseSize(QtCore.QSize(100, 0))
self.connect_btn.setPopupMode(QtWidgets.QToolButton.ToolButtonPopupMode.MenuButtonPopup)
self.connect_btn.setToolButtonStyle(QtCore.Qt.ToolButtonStyle.ToolButtonFollowStyle)
self.connect_btn.setObjectName("connect_btn")
self.settings_layout.addWidget(self.connect_btn)
self.status_lbl = QtWidgets.QLabel(parent=self.bottom_settings_group)