Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
captainwong
jlib
Commits
b9ddedd5
Commit
b9ddedd5
authored
Mar 10, 2020
by
captainwong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jlibqt/CheckBtn
parent
0c479ac8
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
126 additions
and
0 deletions
+126
-0
CheckBtn.cpp
jlib/qt/View/CheckBtn.cpp
+80
-0
CheckBtn.h
jlib/qt/View/CheckBtn.h
+38
-0
qt.vcxproj
jlib/qt/qt.vcxproj
+2
-0
qt.vcxproj.filters
jlib/qt/qt.vcxproj.filters
+6
-0
No files found.
jlib/qt/View/CheckBtn.cpp
0 → 100644
View file @
b9ddedd5
#include "CheckBtn.h"
#include <qevent.h>
#include "../QtUtils.h"
#include "../QtStylesheet.h"
using
namespace
jlib
::
qt
;
CheckBtn
::
CheckBtn
(
QWidget
*
parent
,
int
tag
)
:
QLabel
(
parent
)
,
tag_
(
tag
)
{
setAlignment
(
Qt
::
AlignLeft
|
Qt
::
AlignVCenter
);
}
CheckBtn
::~
CheckBtn
()
{
}
void
CheckBtn
::
set_font_size
(
int
fsz
)
{
font_sz_
=
fsz
;
refresh
();
}
void
CheckBtn
::
refresh
()
{
if
(
pressed_
)
{
setStyleSheet
(
build_style
(
Qt
::
darkGray
,
font_sz_
));
}
else
if
(
hover_
)
{
setStyleSheet
(
build_style
(
Qt
::
lightGray
,
font_sz_
));
}
else
if
(
checked_
)
{
setStyleSheet
(
build_style
(
Qt
::
white
,
font_sz_
));
}
else
{
setStyleSheet
(
build_style
(
Qt
::
darkGray
,
font_sz_
));
}
adjustSize
();
update
();
}
void
CheckBtn
::
set_check
(
bool
check
)
{
MYQDEBUG
<<
check
;
checked_
=
check
;
refresh
();
}
void
CheckBtn
::
enterEvent
(
QEvent
*
e
)
{
setCursor
(
QCursor
(
Qt
::
PointingHandCursor
));
hover_
=
true
;
refresh
();
emit
sig_focus_on
(
tag_
,
true
);
}
void
CheckBtn
::
leaveEvent
(
QEvent
*
e
)
{
setCursor
(
QCursor
(
Qt
::
ArrowCursor
));
hover_
=
false
;
refresh
();
}
void
CheckBtn
::
mousePressEvent
(
QMouseEvent
*
e
)
{
if
(
e
->
button
()
==
Qt
::
LeftButton
)
{
pressed_
=
true
;
refresh
();
}
}
void
CheckBtn
::
mouseReleaseEvent
(
QMouseEvent
*
e
)
{
if
(
pressed_
&&
e
->
button
()
==
Qt
::
LeftButton
)
{
pressed_
=
false
;
checked_
=
!
checked_
;
refresh
();
MYQDEBUG
<<
tag_
<<
checked_
;
emit
sig_check
(
tag_
,
checked_
);
}
}
jlib/qt/View/CheckBtn.h
0 → 100644
View file @
b9ddedd5
#pragma once
#include <QLabel>
class
CheckBtn
:
public
QLabel
{
Q_OBJECT
public
:
CheckBtn
(
QWidget
*
parent
,
int
tag
=
-
1
);
~
CheckBtn
();
void
set_font_size
(
int
fsz
);
void
refresh
();
void
set_check
(
bool
check
=
true
);
bool
is_check
()
const
{
return
checked_
;
}
void
set_tag
(
int
tag
)
{
tag_
=
tag
;
}
int
tag
()
const
{
return
tag_
;
}
protected
:
virtual
void
enterEvent
(
QEvent
*
e
)
override
;
virtual
void
leaveEvent
(
QEvent
*
e
)
override
;
virtual
void
mousePressEvent
(
QMouseEvent
*
e
)
override
;
virtual
void
mouseReleaseEvent
(
QMouseEvent
*
e
)
override
;
signals
:
void
sig_check
(
int
tag
,
bool
is_check
);
void
sig_focus_on
(
int
tag
,
bool
on
);
private
:
bool
pressed_
=
false
;
bool
hover_
=
false
;
bool
checked_
=
false
;
int
tag_
=
-
1
;
int
font_sz_
=
18
;
};
jlib/qt/qt.vcxproj
View file @
b9ddedd5
...
...
@@ -95,12 +95,14 @@
<ClCompile
Include=
"qt.cpp"
/>
<ClCompile
Include=
"View\BaseScrollView.cpp"
/>
<ClCompile
Include=
"View\BgColorBtn.cpp"
/>
<ClCompile
Include=
"View\CheckBtn.cpp"
/>
<ClCompile
Include=
"View\IconBtn.cpp"
/>
<ClCompile
Include=
"View\PageTitle.cpp"
/>
<ClCompile
Include=
"View\RndButton.cpp"
/>
</ItemGroup>
<ItemGroup>
<ClInclude
Include=
"resource.h"
/>
<QtMoc
Include=
"View\CheckBtn.h"
/>
<QtMoc
Include=
"View\BaseScrollView.h"
/>
<QtMoc
Include=
"View\RndButton.h"
/>
<QtMoc
Include=
"View\PageTitle.h"
/>
...
...
jlib/qt/qt.vcxproj.filters
View file @
b9ddedd5
...
...
@@ -48,6 +48,9 @@
<ClCompile
Include=
"View\BaseScrollView.cpp"
>
<Filter>
View
</Filter>
</ClCompile>
<ClCompile
Include=
"View\CheckBtn.cpp"
>
<Filter>
View
</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude
Include=
"qt.h"
>
...
...
@@ -102,5 +105,8 @@
<QtMoc
Include=
"View\BaseScrollView.h"
>
<Filter>
View
</Filter>
</QtMoc>
<QtMoc
Include=
"View\CheckBtn.h"
>
<Filter>
View
</Filter>
</QtMoc>
</ItemGroup>
</Project>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment