Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
SkywardHub
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Avionics
Software Development
SkywardHub
Commits
62cf68aa
Commit
62cf68aa
authored
3 years ago
by
Riccardo Musso
Browse files
Options
Downloads
Patches
Plain Diff
First implementation of tabs with QListWidget and QStackedWidget
parent
d8b691ff
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
Modules/Tabs/tabsmodule.cpp
+79
-16
79 additions, 16 deletions
Modules/Tabs/tabsmodule.cpp
Modules/Tabs/tabsmodule.h
+5
-0
5 additions, 0 deletions
Modules/Tabs/tabsmodule.h
with
84 additions
and
16 deletions
Modules/Tabs/tabsmodule.cpp
+
79
−
16
View file @
62cf68aa
...
...
@@ -6,12 +6,14 @@
TabsModule
::
TabsModule
(
QWidget
*
parent
)
:
DefaultModule
{
parent
}
{
setupUi
();
}
TabsModule
::~
TabsModule
()
{
defaultContextMenuSetup
();
addTab
(
"prova1"
);
addTab
(
"prova2"
);
}
TabsModule
::~
TabsModule
()
{}
QWidget
*
TabsModule
::
toWidget
()
{
return
this
;
...
...
@@ -23,23 +25,82 @@ XmlObject TabsModule::toXmlObject() {
}
void
TabsModule
::
fromXmlObject
(
const
XmlObject
&
xmlObject
)
{
Q_UNUSED
(
xmlObject
);
}
void
TabsModule
::
setupUi
()
{
// --- Left component (centered inside left bar)
QWidget
*
centeredLeft
=
new
QWidget
();
centeredLeft
->
setSizePolicy
(
QSizePolicy
::
Expanding
,
QSizePolicy
::
Fixed
);
QBoxLayout
*
centeredLeftLayout
=
new
QBoxLayout
(
QBoxLayout
::
TopToBottom
,
centeredLeft
);
centeredLeftLayout
->
setContentsMargins
(
0
,
0
,
0
,
0
);
bool
TabsModule
::
removeTab
(
const
QString
&
tabName
)
{
for
(
unsigned
i
=
0
;
i
<
getTabCount
();
i
++
)
{
auto
item
=
tabNames
->
item
(
i
);
if
(
item
->
text
()
==
tabName
)
{
tabNames
->
removeItemWidget
(
item
);
tabContents
->
removeWidget
(
tabContents
->
widget
(
i
));
// TODO select another tab
return
true
;
}
}
return
false
;
}
bool
TabsModule
::
addTab
(
const
QString
&
tabName
,
int
index
)
{
if
(
index
<
0
||
static_cast
<
unsigned
>
(
index
)
>
getTabCount
())
index
=
getTabCount
();
if
(
!
tabNames
->
findItems
(
tabName
,
Qt
::
MatchExactly
).
isEmpty
())
return
false
;
auto
*
listItem
=
new
QListWidgetItem
();
listItem
->
setText
(
tabName
);
listItem
->
setTextAlignment
(
Qt
::
AlignCenter
);
tabNames
->
insertItem
(
index
,
listItem
);
tabContents
->
insertWidget
(
index
,
new
QWidget
(
this
));
return
true
;
}
unsigned
TabsModule
::
getTabCount
()
{
return
tabNames
->
count
();
}
void
TabsModule
::
addCustomActionsToMenu
()
{
}
// ---- UI
constexpr
const
char
*
tabNamesStyleSheet
=
R"x(
QListWidget {
show-decoration-selected: 1;
color: #d7d6d6;
font-weight: bold;
font-size: 16px;
}
QListWidget::item {
padding-top: 10px;
padding-bottom: 10px;
}
QListWidget::item:selected {
border-left-style: solid;
border-left-width: 8px;
border-left-color: #a8a8a9;
background-color: #606060;
}
)x"
;
void
TabsModule
::
setupUi
()
{
// --- Left components
QLabel
*
label
=
new
QLabel
();
QPixmap
skywardLogo
(
":/Resources/Images/LogoWithText.png"
);
label
->
setPixmap
(
skywardLogo
.
scaledToWidth
(
20
0
,
Qt
::
SmoothTransformation
));
centeredLeftLayout
->
addWidget
(
label
);
label
->
setPixmap
(
skywardLogo
.
scaledToWidth
(
15
0
,
Qt
::
SmoothTransformation
));
label
->
setSizePolicy
(
QSizePolicy
::
Fixed
,
QSizePolicy
::
Fixed
);
tabNames
=
new
QListWidget
;
centeredLeftLayout
->
addWidget
(
tabNames
);
tabNames
->
setStyleSheet
(
tabNamesStyleSheet
);
tabNames
->
setSizePolicy
(
QSizePolicy
::
Expanding
,
QSizePolicy
::
Preferred
);
tabNames
->
setSizeAdjustPolicy
(
QAbstractScrollArea
::
AdjustToContents
);
// --- Right component
tabContents
=
new
QStackedWidget
;
...
...
@@ -50,11 +111,13 @@ void TabsModule::setupUi() {
QWidget
*
leftBar
=
new
QWidget
;
leftBar
->
setStyleSheet
(
"background-color: #494949"
);
leftBar
->
setMaximumWidth
(
200
);
leftBar
->
setMaximumWidth
(
300
);
leftBar
->
setSizePolicy
(
QSizePolicy
::
Fixed
,
QSizePolicy
::
Expanding
);
QBoxLayout
*
leftBarLayout
=
new
QBoxLayout
(
QBoxLayout
::
LeftToRight
,
leftBar
);
leftBarLayout
->
setContentsMargins
(
0
,
0
,
0
,
0
);
leftBarLayout
->
addWidget
(
centeredLeft
,
Qt
::
AlignCenter
);
QGridLayout
*
leftBarLayout
=
new
QGridLayout
(
leftBar
);
leftBarLayout
->
setContentsMargins
(
0
,
10
,
0
,
0
);
leftBarLayout
->
addWidget
(
label
,
0
,
0
,
Qt
::
AlignHCenter
);
leftBarLayout
->
addWidget
(
tabNames
,
1
,
0
,
Qt
::
AlignVCenter
);
outerLayout
->
addWidget
(
leftBar
);
outerLayout
->
addWidget
(
tabContents
);
...
...
This diff is collapsed.
Click to expand it.
Modules/Tabs/tabsmodule.h
+
5
−
0
View file @
62cf68aa
...
...
@@ -13,6 +13,11 @@ class TabsModule : public DefaultModule {
TabsModule
(
QWidget
*
parent
=
nullptr
);
~
TabsModule
();
bool
removeTab
(
const
QString
&
tabName
);
bool
addTab
(
const
QString
&
tabName
,
int
index
=
-
1
);
unsigned
getTabCount
();
void
addCustomActionsToMenu
()
override
;
QWidget
*
toWidget
()
override
;
XmlObject
toXmlObject
()
override
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment