Ver Fonte

V1.0
1、完成了对时间选择控件的修改

Apple há 3 semanas atrás
pai
commit
d9efa007c7

+ 1 - 1
External

@@ -1 +1 @@
-Subproject commit 2411453376102eb34dbbbc988b42d627089eab1e
+Subproject commit d9d9ed9a9200275b503ccc44b7d4199a66a61d9b

+ 0 - 55
demo/Component/SelectTime/SelectTime/Res/light/timepartwidget.qss

@@ -1,55 +0,0 @@
-
-QWidget
-{
-    border-radius: 0px;
-    background: #FFFFFF;
-}
-
-
-
-QListWidget
-{
-    font-size: 14px;
-    color: "#3A3F63";
-	border: none;
-	border-right: 1px solid rgba(0, 0, 0, 0.06);
-	background: #ffffff;
-	outline: 0px;
-}
-QListView::item:hover 
-{
-	background-color: rgb(245,245,245);
-    color: "#3A3F63";
-}
-
-QListView::item:selected 
-{
-	background-color: rgb(227, 238, 255);
-    color: "#3A3F63";
-	outline: none;
-}
-
-QScrollBar:vertical
-{
-	border:none;
-    background-color: "#e2e2e2";
-    width: 4px;
-}
-
-QScrollBar::handle:vertical
-{
-	background: #e2e2e2;
-    border-radius: 2px;
-}
-
-QScrollBar::add-line:vertical, QScrollBar::sub-line:vertical
-{
-	background: #ffffff;/*transparent;*/
-    border: none;
-}
-
-QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical
-{
-	background: #ffffff;/*transparent;*/
-    border: none;
-}

+ 7 - 1
demo/Component/SelectTime/SelectTime/Res/light/timepopupwidget.qss

@@ -12,9 +12,15 @@ QWidget
  *  QPushButton
  * ========================================================== */
 
+/* QWidget#widget_pBtn
+{
+    border-top: 1px solid #E6E9F4;
+} */
+
+
 QPushButton
 {
-	font-weight: 500;
+	font-weight: 400;
 	font-size: 14px;
 	text-align: center;
 }

+ 27 - 1
demo/Component/SelectTime/SelectTime/Res/light/timewidget.qss

@@ -8,7 +8,7 @@ QPushButton[selected=true]
 	border-image: url(:/Res/image/time.png);
 }
 
-QPushButton::hover[selected=true]
+QPushButton:hover[selected=true]
 {
 	border-image: url(:/Res/image/time.png);
 }
@@ -23,6 +23,19 @@ QDateTimeEdit
  *  TimeWidget
  * ========================================================== */
 
+QDateTimeEdit
+{
+	background: transparent;
+	border: none;
+}
+
+/* QTimeEdit:disabled
+{
+	background: transparent;
+	border: none;
+} */
+
+
 TimeWidget
 {
 	background: #FFFFFF;
@@ -34,6 +47,19 @@ TimeWidget
 	color: #3A3F63;
 }
 
+TimeWidget:disabled
+{
+	background: rgba(0, 0, 0, 0.04);
+	border-radius: 4px;
+	border: 1px solid #E6E9F4;
+	padding-left: 12px;
+	font-weight: 400;
+	font-size: 14px;
+	color: #3A3F63;
+}
+
+
+
 TimeWidget:hover
 {
 	border: 1px solid #4458FE;

+ 3 - 3
demo/Component/SelectTime/SelectTime/SelectTime.qrc

@@ -1,10 +1,10 @@
+<!DOCTYPE RCC>
 <RCC>
-    <qresource prefix="/">
+  <qresource prefix="/">
     <file>Res/image/time.png</file>
-    <file>Res/light/timepartwidget.qss</file>
     <file>Res/light/timewidget.qss</file>
     <file>Res/light/timepopupwidget.qss</file>
     <file>Res/dark/timepartwidget.qss</file>
     <file>Res/dark/timewidget.qss</file>
-    </qresource>
+  </qresource>
 </RCC>

+ 3 - 3
demo/Component/SelectTime/SelectTime/timepopupwidget.ui

@@ -15,7 +15,7 @@
   </property>
   <layout class="QVBoxLayout" name="verticalLayout">
    <property name="spacing">
-    <number>4</number>
+    <number>6</number>
    </property>
    <property name="leftMargin">
     <number>0</number>
@@ -107,7 +107,7 @@
         <property name="minimumSize">
          <size>
           <width>52</width>
-          <height>26</height>
+          <height>24</height>
          </size>
         </property>
         <property name="text">
@@ -126,7 +126,7 @@
         <property name="minimumSize">
          <size>
           <width>52</width>
-          <height>26</height>
+          <height>24</height>
          </size>
         </property>
         <property name="text">

+ 62 - 49
demo/Component/SelectTime/SelectTime/timewidget.cpp

@@ -11,7 +11,7 @@
 #include "spdlog/spdlog.h"
 #include "timepopupwidget.h"
 
-TimeWidget::TimeWidget(QWidget *parent , ShowType type) :
+TimeWidget::TimeWidget(QWidget *parent, ShowType type) :
     QFrame(parent),
     ui(new Ui::TimeWidget),
     m_wdgTimeArea(nullptr),
@@ -23,16 +23,16 @@ TimeWidget::TimeWidget(QWidget *parent , ShowType type) :
 }
 
 
-TimeWidget::TimeWidget(ShowType type) : 
-    QFrame(nullptr),
-    ui(new Ui::TimeWidget),
-    m_wdgTimeArea(nullptr),
-    m_pMainWindow(nullptr),
-    m_type(type)
-{
-    ui->setupUi(this);
-    Init();
-}
+// TimeWidget::TimeWidget(ShowType type) : 
+//     QFrame(nullptr),
+//     ui(new Ui::TimeWidget),
+//     m_wdgTimeArea(nullptr),
+//     m_pMainWindow(nullptr),
+//     m_type(type)
+// {
+//     ui->setupUi(this);
+//     Init();
+// }
 
 TimeWidget::~TimeWidget()
 {
@@ -58,35 +58,6 @@ QTime TimeWidget::getTime()
 }
 
 
-/**
- * @brief 存在时间就返回hh:mm:ss.zzz格式字符串,否则返回提示信息
- * @return
- */
-// QString TimeWidget::getTimeStr()
-// {
-//     QString ret(ui->lbl_tip->text());
-//     if (!ui->dateTimeEdit->isHidden()) {
-//         ret = ui->dateTimeEdit->time().toString("hh:mm:ss");//.zzz
-//     }
-//     return ret;
-// }
-/**
- * @brief 存在返回时间,否则返回00:00:00
- * @return
- */
-// QTime TimeWidget::getFormTime() const
-// {
-//     return ui->dateTimeEdit->isHidden() ? QTime(0, 0, 0) : ui->dateTimeEdit->time();
-// }
-
-// void TimeWidget::setTime(const QString& t)
-// {
-//     QTime time = QTime::fromString(t, "hh:mm:ss");
-//     ui->dateTimeEdit->setTime(time);
-//     ui->lbl_tip->hide();
-//     ui->dateTimeEdit->show();
-//     UpdatePopupTime(ui->dateTimeEdit->dateTime());//
-// }
 
 void TimeWidget::setTime(const QTime& t)
 {
@@ -184,6 +155,27 @@ void TimeWidget::setWheelDisabled(bool disabled)
     m_isDisableWheel = disabled;
 }
 
+
+/* 设置启用与否*/
+void TimeWidget::setEditLineEnable(bool enable)
+{
+    this->setEnabled(enable);
+    if(!enable)
+    {
+        if(m_pTimePopupWidget != nullptr && m_pTimePopupWidget->isVisible())
+        {
+            m_isBanPopupShow = true;
+            ShowPopupArea(false);
+            UpdateProperty(this, "hover", false);
+        }
+        ui->btn_tip->hide();
+    }else 
+    {
+        ui->btn_tip->show();
+    }
+}
+
+
 /* 设置QSS */
 void TimeWidget::setQSS()
 {
@@ -242,13 +234,16 @@ bool TimeWidget::eventFilter(QObject* obj, QEvent* e)
         if (e->type() == QEvent::FocusIn && m_type == EditLine)
         {
             /* 如果Popup正在关闭 */
-            if(m_isBanPopupShow == true)
-            {
-                m_isBanPopupShow = false;
-                /* 这里需要再次失去焦点,否则下次点击编辑栏无法弹出Popup */
-                ui->dateTimeEdit->clearFocus();
-                return QWidget::eventFilter(obj, e);
-            }
+
+                if(m_isBanPopupShow == true)
+                {
+                    m_isBanPopupShow = false;
+                    /* 这里需要再次失去焦点,否则下次点击编辑栏无法弹出Popup */
+                    ui->dateTimeEdit->clearFocus();
+                    return QWidget::eventFilter(obj, e);
+                }
+            
+            
             //qInfo() << "dateTimeEdit focusIn";
             ShowPopupArea(true);
             UpdateProperty(ui->btn_tip, "selected", true);
@@ -299,7 +294,12 @@ bool TimeWidget::eventFilter(QObject* obj, QEvent* e)
                 {
                     return QWidget::eventFilter(obj, e);
                 }
-                m_isBanPopupShow = true;
+                /* 如果焦点不在编辑栏,Popup窗口隐藏后,编辑栏会重新获取焦点,将会再次跳出Popup窗口
+                    因此在其没有焦点的时候设置 m_isBanPopupShow ,防止Popup隐藏后编辑栏再次获取焦点再次弹出Popup */
+                if(!ui->dateTimeEdit->hasFocus())
+                {
+                    m_isBanPopupShow = true;
+                }
                 
                 ShowPopupArea(false);
                 UpdateProperty(this, "hover", false);
@@ -429,7 +429,7 @@ void TimeWidget::ShowPopupArea(bool bShow)
             /* 设置弹窗Popup的大小,使用默认的固定大小,不允许改变
                关于高度:确定取消按钮所占的高度是固定的32,和一节大小一样,所以这里 */
             int width = 2 * SHADOW_MARGIN + TIME_AREA_WIDTH * m_vecTimeSections.size();
-            int height = TIME_AREA_HEIGHT * 7 + 2 * SHADOW_MARGIN;
+            int height = TIME_AREA_HEIGHT * 7 + 2 * SHADOW_MARGIN + 8;
             m_wdgTimeArea->resize(QSize(width, height));
             UpdatePopupTime(ui->dateTimeEdit->dateTime());
             /* 保存现在的时间 */
@@ -513,8 +513,21 @@ void TimeWidget::Init()
     }
     ui->btn_tip->setProperty("selected", false);
 
+    /* 设置时间图标大小 */
+    ui->btn_tip->setFixedSize(16, 16);
+
+    /* 设置初始值 */
+    QTime t(0, 0, 0);
+    ui->dateTimeEdit->setTime(t);
+    ui->lbl_tip->hide();
+    /* 使用这个阻止show的时候获取焦点自动弹出Popup */
+    m_isBanPopupShow = true;
+    ui->dateTimeEdit->show();
+    m_formerDateTime.setTime(t);
+
     connect(ui->btn_tip, &QPushButton::clicked, this, &TimeWidget::do_pBtn_tip_Clicked);
     connect(ui->dateTimeEdit, &QDateTimeEdit::dateTimeChanged, this, &TimeWidget::onDateTimeChanged);
 
     // setDefaultStyle();
+    
 }

+ 4 - 5
demo/Component/SelectTime/SelectTime/timewidget.h

@@ -40,16 +40,13 @@ public:
         EditLine = 0,           /* 时间编辑栏 */
         Dialog = 1,             /* 以弹窗的形式出现 */
     };
-    explicit TimeWidget(QWidget *parent = nullptr , ShowType type = EditLine);
-    explicit TimeWidget(ShowType type = EditLine);
+    explicit TimeWidget(QWidget *parent = nullptr, ShowType type = EditLine);
+    // explicit TimeWidget(ShowType type = EditLine);
     ~TimeWidget();
 
     // 在父窗口无法容纳控件时,这是必要的
     void SetMainWindow(QWidget* pWidget);
     QTime getTime();
-    // QString getTimeStr();
-    // QTime getFormTime() const;
-    // void setTime(const QString& t);
     void setTime(const QTime& t);
     void clearTime();
     QString tipText() const;
@@ -69,6 +66,8 @@ public:
     void setEditLine(int w, int h);
     /* 设置禁止使用滚轮修改时间 */
     void setWheelDisabled(bool disabled);
+    /* 设置启用与否*/
+    void setEditLineEnable(bool enable);
 
     /* 设置QSS */
     void setQSS();

+ 11 - 0
demo/Component/SelectTime/widget.cpp

@@ -15,6 +15,7 @@ Widget::Widget(QWidget *parent)
 {
     ui->setupUi(this);
 
+    ui->timeEdit->resize(160, 32);
     connect(ui->timeEdit, &TimeWidget::signal_timeChanged, this, &Widget::do_timeEdit_timeChanged);
 
     SPDLOG_INFO("***** Qt Library *****");
@@ -32,3 +33,13 @@ void Widget::do_timeEdit_timeChanged(const QTime &formerTime, const QTime &time)
     SPDLOG_INFO("时间改变了: {} -> {}", formerTime.toString("HH:mm:ss").toStdString(), time.toString("HH:mm:ss").toStdString());
 }
 
+
+void Widget::on_pBtn_disable_clicked()
+{
+    ui->timeEdit->setEditLineEnable(false);
+}
+
+void Widget::on_pBtn_enable_clicked()
+{
+    ui->timeEdit->setEditLineEnable(true);
+}

+ 4 - 0
demo/Component/SelectTime/widget.h

@@ -21,6 +21,10 @@ private slots:
     /* 时间改变了 */
     void do_timeEdit_timeChanged(const QTime &formerTime, const QTime &time);
 
+    void on_pBtn_disable_clicked();
+
+    void on_pBtn_enable_clicked();
+
 private:
     Ui::Widget *ui;
 

+ 32 - 0
demo/Component/SelectTime/widget.ui

@@ -13,6 +13,12 @@
   <property name="windowTitle">
    <string>Widget</string>
   </property>
+  <property name="styleSheet">
+   <string notr="true">QWidget
+{
+	background-color: #FFFFFF;
+}</string>
+  </property>
   <widget class="TimeWidget" name="timeEdit">
    <property name="geometry">
     <rect>
@@ -23,6 +29,32 @@
     </rect>
    </property>
   </widget>
+  <widget class="QPushButton" name="pBtn_disable">
+   <property name="geometry">
+    <rect>
+     <x>400</x>
+     <y>110</y>
+     <width>80</width>
+     <height>26</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>禁用</string>
+   </property>
+  </widget>
+  <widget class="QPushButton" name="pBtn_enable">
+   <property name="geometry">
+    <rect>
+     <x>510</x>
+     <y>110</y>
+     <width>80</width>
+     <height>26</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>启用</string>
+   </property>
+  </widget>
  </widget>
  <customwidgets>
   <customwidget>