diff --git a/Static/Main.qss b/Static/Main.qss index 9dcca0b..8a53d0d 100644 --- a/Static/Main.qss +++ b/Static/Main.qss @@ -1,16 +1,3 @@ - -QMdiSubWindow { - - font-size: 18px; - - font-weight: bold; - -} - - - - - QComboBox#dataTypeCombox, QComboBox#orderCombox{ font-size: 20px; @@ -32,50 +19,6 @@ QTabBar::close-button:hover { } -QTabBar::tab:hover { - - background-color: #cbdeec; - -} - - -QTabBar::tab{ - - background: #f0f0f0; - - /* border: 2px;*/ - - min-width: 200px; - - min-height: 40px; - - font: 20px; - - font-family: ".SFNSDisplay-Regular"; - -} - -QTabBar#areaTabBar::tab{ - -/* min-width: 100px;*/ - - font: 20px; - -} - - -QTabBar::tab:selected { - - background-color: #809ac2; - - font: bold; - - border-radius: 3px; - - margin-bottom: -4px - - -} QDockWidget{ @@ -86,7 +29,9 @@ QDockWidget{ font-family: ".SFNSDisplay-Regular"; - border: 1px solid black; +/* border: 1px solid black;*/ + + border: none; } @@ -94,15 +39,13 @@ QDockWidget::title{ font-size: 20px; - background-color: #cbdeec; + background-color: #2084F6; color: white; text-align: center; - - } @@ -151,11 +94,14 @@ QWidget#deviceWidget{ border: 1px solid gray; + } -QTabWidget::tab-bar{ +QTabWidget{ - background-color: black; + border: none; + + background-color: white; } \ No newline at end of file diff --git a/Static/newH.png b/Static/newH.png deleted file mode 100644 index 4b21487..0000000 Binary files a/Static/newH.png and /dev/null differ diff --git a/Static/startProtocol.png b/Static/startProtocol.png deleted file mode 100644 index e7bb4a9..0000000 Binary files a/Static/startProtocol.png and /dev/null differ diff --git a/Static/varMagH.png b/Static/varMagH.png deleted file mode 100644 index 1d94c1e..0000000 Binary files a/Static/varMagH.png and /dev/null differ diff --git a/UI/AreaTabWidget.py b/UI/AreaTabWidget.py index ea0bdcc..24c83f0 100644 --- a/UI/AreaTabWidget.py +++ b/UI/AreaTabWidget.py @@ -144,6 +144,8 @@ class AreaWidget(QWidget): self.leftLayout = QGridLayout() self.rightLayout = QGridLayout() self.mainLayout.setContentsMargins(0, 0, 0, 0) + self.leftLayout.setContentsMargins(0, 0, 0, 0) + self.rightLayout.setContentsMargins(0, 0, 0, 0) LimitData = self.devicesManange.getLimitData(self.areaTabWidget.deviceName) diff --git a/UI/DeviceWidget.py b/UI/DeviceWidget.py index dd174d7..5de160e 100644 --- a/UI/DeviceWidget.py +++ b/UI/DeviceWidget.py @@ -1,6 +1,7 @@ import json -from PyQt5.QtWidgets import QMainWindow, QDialog, QTabWidget, QPushButton, QSpacerItem, QSizePolicy,QMessageBox, QHBoxLayout, QWidget +from PyQt5.QtWidgets import QMainWindow, QDialog, QTabWidget, QPushButton, QSpacerItem, QSizePolicy\ + ,QMessageBox, QHBoxLayout, QWidget, QTabBar, QProxyStyle, QStyle from PyQt5.QtGui import QIcon from PyQt5.QtCore import QSize @@ -13,7 +14,212 @@ from utils.DBModels.DeviceModels import DeviceDB from model.ProjectModel.DeviceManage import DevicesManange from UI.DeviceDialogWidget import DeviceDialog -class DeviceWidget(QTabWidget): +from PyQt5.QtWidgets import QApplication, QStyleOptionTab, QTabBar, QWidget +from PyQt5.QtGui import QPainter, QPen, QColor, QPainterPath, QPolygonF, QFontMetrics, QTextOption, QFont +from PyQt5.QtCore import Qt, QRectF, QPointF + +class NewChromeTabStyle(QProxyStyle): + def drawControl(self, element, option, painter, widget): + # painter.save() + # painter.setPen(Qt.red); + # painter.restore(); + if element == QStyle.CE_TabBarTabLabel: + tab = option + # print(type(tab)) + textRect = QRectF(self.subElementRect(QStyle.SE_TabBarTabText, tab, widget)) + painter.save() + if (tab.state & QStyle.State_Selected): + painter.setPen(QPen(QColor("black"))) + elif (tab.state & QStyle.State_MouseOver): + painter.setPen(QPen(QColor("black"))) + else: + painter.setPen(QPen(QColor("black"))) + option = QTextOption() + # 设置对齐方式,Qt.AlignLeft 和 Qt.AlignVCenter 分别对应左对齐和垂直居中 + font = QFont(); + font.setPointSize(20); + painter.setFont(font); + + option.setAlignment(Qt.AlignCenter | Qt.AlignVCenter) + # 设置换行模式为不换行 + option.setWrapMode(QTextOption.NoWrap) + painter.drawText(textRect, tab.text, option) + painter.restore() + + + elif element == QStyle.CE_TabBarTabShape: + tab = option + painter.setRenderHint(QPainter.Antialiasing); + + shapeRect = QRectF(tab.rect); + arcLen = shapeRect.height() / 2; + + if (tab.state & QStyle.State_Selected): + painter.save(); + pen = QPen(Qt.red); + pen.setWidthF(0.5); + painter.setPen(pen); + painter.restore(); + + painter.save(); + shapeRect.setX(shapeRect.x() - arcLen); + shapeRect.setWidth(shapeRect.width() + arcLen *3/ 4); + + path = QPainterPath(); + + arcRect1 = QRectF(shapeRect.x(), + shapeRect.y() + shapeRect.height() / 3, + arcLen, + shapeRect.height() * 2 / 3); + + path.moveTo(QPointF(arcRect1.x(), + arcRect1.y() + arcRect1.height())); + + path.lineTo(QPointF(arcRect1.x() + arcRect1.width() / 2, + arcRect1.y() + arcRect1.height())); + + # // Starting from 270°, returning to the arc of 90° + path.arcTo(arcRect1, 270.0, 90.0); + + path.lineTo(QPointF(arcRect1.x() + arcRect1.width(), + arcRect1.y())); + + arcRect2 = QRectF(shapeRect.x() + arcRect1.width(), + shapeRect.y(), + arcLen, + shapeRect.height() * 2 / 3); + + # // Starting from 180°, returning to the arc of -90° + path.arcTo(arcRect2, 180.0, -90.0); + + path.lineTo(QPointF(arcRect2.x() + shapeRect.width() - 2 * (arcRect2.x() + arcRect2.width()) + arcRect2.width() / 2, + arcRect2.y())); + + arcRect3 = QRectF(shapeRect.x() + shapeRect.width() - 2 * arcRect1.width(), + shapeRect.y(), + arcRect1.width(), + shapeRect.height() * 2 / 3); + + path.arcTo(arcRect3, 90.0, -90.0); + + path.lineTo(QPointF(arcRect3.x() + arcRect3.width(), + arcRect3.y() + arcRect3.height())); + + arcRect4 = QRectF(arcRect3.x() + arcRect3.width(), + arcRect3.y() + arcRect3.height() / 2, + arcRect1.width(), + shapeRect.height() * 2 / 3); + + path.arcTo(arcRect4, 180.0, 90.0); + + path.lineTo(QPointF(arcRect1.x(), + arcRect1.y() + arcRect1.height())); + + painter.setPen(Qt.NoPen); + painter.setBrush(Qt.blue); + polygon = path.toFillPolygon(); + painter.drawPolygon(polygon); + + painter.restore(); + elif (tab.state & QStyle.State_MouseOver): + painter.save(); + pen = QPen(Qt.black); + pen.setWidthF(0.5); + painter.setPen(pen); + + painter.restore(); + painter.save(); + + shapeRect.setX(shapeRect.x() - arcLen); + shapeRect.setWidth(shapeRect.width() + arcLen *3/ 4); + + path = QPainterPath() + + arcRect1 = QRectF(shapeRect.x(), + shapeRect.y() + shapeRect.height() / 3, + arcLen, + shapeRect.height() * 2 / 3); + + path.moveTo(QPointF(arcRect1.x(), + arcRect1.y() + arcRect1.height())); + + path.lineTo(QPointF(arcRect1.x() + arcRect1.width() / 2, + arcRect1.y() + arcRect1.height())); + + path.arcTo(arcRect1, 270.0, 90.0); + + path.lineTo(QPointF(arcRect1.x() + arcRect1.width(), + arcRect1.y())); + + arcRect2 = QRectF(shapeRect.x() + arcRect1.width(), + shapeRect.y(), + arcLen, + shapeRect.height() * 2 / 3); + + path.arcTo(arcRect2, 180.0, -90.0); + + path.lineTo(QPointF(arcRect2.x() + shapeRect.width() - 2 * (arcRect2.x() + arcRect2.width()) + arcRect2.width() / 2, + arcRect2.y())); + + arcRect3 = QRectF(shapeRect.x() + shapeRect.width() - 2 * arcRect1.width(), + shapeRect.y(), + arcRect1.width(), + shapeRect.height() * 2 / 3); + + path.arcTo(arcRect3, 90.0, -90.0); + + path.lineTo(QPointF(arcRect3.x() + arcRect3.width(), + arcRect3.y() + arcRect3.height())); + + arcRect4 = QRectF(arcRect3.x() + arcRect3.width(), + arcRect3.y() + arcRect3.height() / 2, + arcRect1.width(), + shapeRect.height() * 2 / 3); + + path.arcTo(arcRect4, 180.0, 90.0); + + path.lineTo(QPointF(arcRect1.x(), + arcRect1.y() + arcRect1.height())); + + painter.setPen(Qt.NoPen); + painter.setBrush(QColor("yellow")); + polygon = path.toFillPolygon(); + painter.drawPolygon(polygon); + + painter.restore(); + + else: + painter.save(); + + shapeRect.setX(shapeRect.x() - arcLen); + shapeRect.setWidth(shapeRect.width() + arcLen / 2); + + pen = QPen(Qt.white); + pen.setWidthF(0.5); + painter.setPen(pen); + + + painter.restore(); + else: + super(NewChromeTabStyle, self).drawControl(element, option, painter, widget); + + + +class DeviceTabBar(QTabBar): + def __init__(self): + super().__init__() + self.setStyle(NewChromeTabStyle()) + + def tabSizeHint(self, index): + newSize = QTabBar().tabSizeHint(index) + width = len(self.tabText(index)) * 20 + 100 + newSize.setWidth(width) + newSize.setHeight(40) + + return newSize + + +class DeviceTab(QTabWidget): def __init__(self, dockWidget, devicesManange): super().__init__() self.dockWidget = dockWidget @@ -23,6 +229,8 @@ class DeviceWidget(QTabWidget): def initUI(self): + # self.tabBar = DeviceTabBar() + self.setTabBar(DeviceTabBar()) #获取DP、PA协议和主从模式 self.dataTypeAndModel = self.dockWidget.windowTitle() self.proType = self.dataTypeAndModel[0:2] @@ -118,6 +326,8 @@ class DeviceWidget(QTabWidget): widget.setLayout(layout) self.addTab(widget,'') self.tabBar().setHidden(True) + + diff --git a/UI/MainWindow.py b/UI/MainWindow.py index 9022a39..7b45eef 100644 --- a/UI/MainWindow.py +++ b/UI/MainWindow.py @@ -13,7 +13,7 @@ from PyQt5.QtCore import Qt, QTimer, QSize from PyQt5.QtGui import QIcon, QWindow from utils.DBModels.BaseModel import * from model.ClientModel.Client import Client -from UI.DeviceWidget import DeviceWidget +from UI.DeviceWidget import DeviceTab from model.ProjectModel.DeviceManage import DevicesManange @@ -78,19 +78,19 @@ class MainWindow(QWidget): toolbarLayout.setContentsMargins(0, 0, 0, 0) dpMasterDockWidget = QDockWidget('DP主站') - dpMasterDockWidget.setWidget(DeviceWidget(dpMasterDockWidget, self.devicesManange)) + dpMasterDockWidget.setWidget(DeviceTab(dpMasterDockWidget, self.devicesManange)) dpMasterDockWidget.setFeatures(QDockWidget.DockWidgetMovable | QDockWidget.DockWidgetFloatable) # type: ignore dpSlaveDockWidget = QDockWidget('DP从站') - dpSlaveDockWidget.setWidget(DeviceWidget(dpSlaveDockWidget, self.devicesManange)) + dpSlaveDockWidget.setWidget(DeviceTab(dpSlaveDockWidget, self.devicesManange)) dpSlaveDockWidget.setFeatures(QDockWidget.DockWidgetMovable | QDockWidget.DockWidgetFloatable) # type: ignore paMasterDockWidget = QDockWidget('PA主站') - paMasterDockWidget.setWidget(DeviceWidget(paMasterDockWidget, self.devicesManange)) + paMasterDockWidget.setWidget(DeviceTab(paMasterDockWidget, self.devicesManange)) paMasterDockWidget.setFeatures(QDockWidget.DockWidgetMovable | QDockWidget.DockWidgetFloatable) # type: ignore paSlaveDockWidget = QDockWidget('PA从站') - paSlaveDockWidget.setWidget(DeviceWidget(paSlaveDockWidget, self.devicesManange)) + paSlaveDockWidget.setWidget(DeviceTab(paSlaveDockWidget, self.devicesManange)) paSlaveDockWidget.setFeatures(QDockWidget.DockWidgetMovable | QDockWidget.DockWidgetFloatable) # type: ignore diff --git a/bin.py b/bin.py index 2df3bbc..4fb965a 100644 --- a/bin.py +++ b/bin.py @@ -8,7 +8,7 @@ import sys if __name__ == '__main__': app = QApplication(sys.argv) - app.setStyle(QStyleFactory.create('windowsvista')) + app.setStyle(QStyleFactory.create('fusion')) app.setStyleSheet(CommonHelper.readQss('static/main.qss') + CommonHelper.readQss('static/Area.qss')) Client.initDB()