├── .gitignore ├── CollapsibleFrame.pro ├── README.md ├── closed.png ├── closed_hover.png ├── collapsibleframe.cpp ├── collapsibleframe.h ├── extendedqlabel.cpp ├── extendedqlabel.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── open.png ├── open_hover.png └── resources.qrc /.gitignore: -------------------------------------------------------------------------------- 1 | *.user 2 | -------------------------------------------------------------------------------- /CollapsibleFrame.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2012-05-05T15:36:58 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui 8 | 9 | TARGET = CollapsibleFrame 10 | TEMPLATE = app 11 | 12 | 13 | SOURCES += main.cpp\ 14 | mainwindow.cpp \ 15 | collapsibleframe.cpp \ 16 | extendedqlabel.cpp 17 | 18 | HEADERS += mainwindow.h \ 19 | collapsibleframe.h \ 20 | extendedqlabel.h 21 | 22 | FORMS += 23 | 24 | RESOURCES += \ 25 | resources.qrc 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Qt-Collapsible-Panel 2 | ==================== 3 | 4 | Collapsible panel implemented in Qt. 5 | 6 | This widget is to be used as sort of an accordion control. Widgets can be added to the widget area and will be shown or hidden. 7 | 8 | Copyright 2012 Cameron Tinker 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | http://www.apache.org/licenses/LICENSE-2.0 14 | 15 | Unless required by applicable law or agreed to in writing, software 16 | distributed under the License is distributed on an "AS IS" BASIS, 17 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | See the License for the specific language governing permissions and 19 | limitations under the License. 20 | -------------------------------------------------------------------------------- /closed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pcmantinker/Qt-Collapsible-Panel/835739a6dd0f74a401b230fe8bb8930d5279a522/closed.png -------------------------------------------------------------------------------- /closed_hover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pcmantinker/Qt-Collapsible-Panel/835739a6dd0f74a401b230fe8bb8930d5279a522/closed_hover.png -------------------------------------------------------------------------------- /collapsibleframe.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012 Cameron Tinker 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #include "collapsibleframe.h" 18 | 19 | CollapsibleFrame::CollapsibleFrame(QObject *parent, QString headerText) 20 | { 21 | m_headerText = headerText; 22 | m_parent = parent; 23 | m_frameState = CLOSED; 24 | 25 | m_headerArea = new QWidget; 26 | m_widgetArea = new QWidget; 27 | m_headerArea->setMaximumHeight(20); 28 | m_widgetArea->setMaximumHeight(1000); 29 | this->setMaximumHeight(1000); 30 | this->setMinimumHeight(20); 31 | 32 | this->setStyleSheet("QWidget { border: 1px solid #000000; }"); 33 | 34 | icon = new ExtendedQLabel; 35 | icon->setMaximumSize(15, 15); 36 | icon->setPixmap(m_collapseIcon); 37 | connect(icon, SIGNAL(clicked()), this, SLOT(changeState())); 38 | 39 | headerTextLabel = new QLabel; 40 | headerTextLabel->setText(m_headerText); 41 | 42 | ExtendedQLabel* test = new ExtendedQLabel; 43 | test->setText("Testing"); 44 | test->setMaximumSize(50,20); 45 | 46 | widgetLayout = new QVBoxLayout; 47 | widgetLayout->setMargin(0); 48 | // widgetLayout->setSpacing(0); 49 | m_widgetArea->setLayout(widgetLayout); 50 | // m_widgetArea->setMaximumHeight(20); 51 | widgetLayout->addWidget(test); /*, 0, Qt::AlignTop | Qt:: AlignLeft);*/ 52 | 53 | QHBoxLayout* headerLayout = new QHBoxLayout; 54 | headerLayout->setMargin(0); 55 | headerLayout->addWidget(icon); /*, 0, Qt::AlignTop | Qt:: AlignLeft);*/ 56 | headerLayout->addWidget(headerTextLabel); /*, 0, Qt::AlignTop | Qt:: AlignLeft);*/ 57 | m_headerArea->setLayout(headerLayout); 58 | 59 | QVBoxLayout* mainLayout = new QVBoxLayout; 60 | mainLayout->setMargin(0); 61 | mainLayout->setSpacing(0); 62 | mainLayout->addWidget(m_headerArea);/*, 0, Qt::AlignTop | Qt:: AlignLeft);*/ 63 | mainLayout->addWidget(m_widgetArea);/*, 0, Qt::AlignTop | Qt:: AlignLeft);*/ 64 | 65 | setLayout(mainLayout); 66 | show(); 67 | determineIcon(); 68 | } 69 | 70 | CollapsibleFrame::~CollapsibleFrame() 71 | { 72 | delete m_headerArea; 73 | delete m_widgetArea; 74 | } 75 | 76 | void CollapsibleFrame::determineIcon() 77 | { 78 | if(m_frameState == OPEN) 79 | { 80 | icon->setStyleSheet("QLabel { image: url(:/open.png) no-repeat; } QLabel:hover { image: url(:/open_hover.png) no-repeat; }"); 81 | icon->setToolTip("Close"); 82 | m_widgetArea->show(); 83 | } 84 | else 85 | { 86 | icon->setStyleSheet("QLabel { image: url(:/closed.png) no-repeat; } QLabel:hover { image: url(:/closed_hover.png) no-repeat; }"); 87 | icon->setToolTip("Open"); 88 | m_widgetArea->hide(); 89 | } 90 | } 91 | 92 | void CollapsibleFrame::changeState() 93 | { 94 | if(m_frameState == OPEN) 95 | { 96 | m_frameState = CLOSED; 97 | headerTextLabel->setText("Closed"); 98 | m_widgetArea->hide(); 99 | } 100 | else 101 | { 102 | m_frameState = OPEN; 103 | headerTextLabel->setText("Open"); 104 | m_widgetArea->show(); 105 | } 106 | determineIcon(); 107 | } 108 | 109 | void CollapsibleFrame::addWidget(QWidget * widget) 110 | { 111 | widgetLayout->addWidget(widget); 112 | } 113 | 114 | void CollapsibleFrame::addLayout(QLayout *layout) 115 | { 116 | widgetLayout->addLayout(layout); 117 | } 118 | 119 | -------------------------------------------------------------------------------- /collapsibleframe.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012 Cameron Tinker 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #ifndef COLLAPSIBLEFRAME_H 18 | #define COLLAPSIBLEFRAME_H 19 | #include 20 | #include "extendedqlabel.h" 21 | #include "extendedqlabel.h" 22 | 23 | class CollapsibleFrame : public QWidget 24 | { 25 | Q_OBJECT 26 | private: 27 | QWidget* m_headerArea; 28 | QPixmap m_collapseIcon; 29 | QString m_headerText; 30 | QWidget* m_widgetArea; 31 | ExtendedQLabel* icon; 32 | QLabel* headerTextLabel; 33 | QVBoxLayout* widgetLayout; 34 | int m_frameState; 35 | void determineIcon(); 36 | QObject* m_parent; 37 | 38 | public: 39 | ~CollapsibleFrame(); 40 | CollapsibleFrame(QObject *parent, QString headerText); 41 | void addWidget(QWidget *widget); 42 | void addLayout(QLayout *layout); 43 | enum { OPEN, CLOSED }; 44 | 45 | private slots: 46 | void changeState(); 47 | }; 48 | 49 | #endif // COLLAPSIBLEFRAME_H 50 | -------------------------------------------------------------------------------- /extendedqlabel.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012 Cameron Tinker 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #include "extendedqlabel.h" 18 | 19 | ExtendedQLabel::ExtendedQLabel(const QString& text, QWidget * parent): 20 | QLabel(parent) 21 | 22 | { 23 | this->setText(text); 24 | } 25 | 26 | ExtendedQLabel::~ExtendedQLabel() 27 | { 28 | 29 | } 30 | 31 | void ExtendedQLabel::mouseReleaseEvent(QMouseEvent *ev) 32 | { 33 | emit clicked(); 34 | } 35 | 36 | void ExtendedQLabel::mouseMoveEvent(QMouseEvent *ev) 37 | { 38 | emit hover(); 39 | } 40 | -------------------------------------------------------------------------------- /extendedqlabel.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012 Cameron Tinker 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #ifndef EXTENDEDQLABEL_H 18 | #define EXTENDEDQLABEL_H 19 | 20 | #include 21 | #include 22 | 23 | class ExtendedQLabel : public QLabel 24 | { 25 | Q_OBJECT 26 | public: 27 | explicit ExtendedQLabel( const QString& text ="", QWidget * parent = 0 ); 28 | ~ExtendedQLabel(); 29 | 30 | signals: 31 | void clicked(); 32 | void hover(); 33 | 34 | protected: 35 | void mouseReleaseEvent(QMouseEvent *ev); 36 | void mouseMoveEvent(QMouseEvent *ev); 37 | }; 38 | 39 | #endif // EXTENDEDQLABEL_H 40 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012 Cameron Tinker 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #include 18 | #include "mainwindow.h" 19 | 20 | int main(int argc, char *argv[]) 21 | { 22 | QApplication a(argc, argv); 23 | MainWindow w; 24 | w.show(); 25 | 26 | return a.exec(); 27 | } 28 | -------------------------------------------------------------------------------- /mainwindow.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012 Cameron Tinker 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #include "mainwindow.h" 18 | #include "ui_mainwindow.h" 19 | 20 | MainWindow::MainWindow(QWidget *parent) 21 | { 22 | // setWindowFlags( 23 | // #ifdef Q_OS_MAC 24 | // Qt::SubWindow | // This type flag is the second point 25 | // #else 26 | // Qt::Tool | 27 | // #endif 28 | // Qt::WindowSystemMenuHint | 29 | // Qt::WindowStaysOnTopHint 30 | // ); 31 | QVBoxLayout* layout = new QVBoxLayout; 32 | layout->setMargin(0); 33 | CollapsibleFrame* cf = new CollapsibleFrame(this, "Test"); 34 | CollapsibleFrame* cf2 = new CollapsibleFrame(cf, "Test2"); 35 | CollapsibleFrame* cf3 = new CollapsibleFrame(this, "Test3"); 36 | cf->addWidget(cf2); 37 | layout->addWidget(cf); 38 | layout->addWidget(cf3); 39 | this->setLayout(layout); 40 | } 41 | 42 | MainWindow::~MainWindow() 43 | { 44 | 45 | } 46 | -------------------------------------------------------------------------------- /mainwindow.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012 Cameron Tinker 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #ifndef MAINWINDOW_H 18 | #define MAINWINDOW_H 19 | 20 | #include 21 | #include "collapsibleframe.h" 22 | 23 | class MainWindow : public QWidget 24 | { 25 | Q_OBJECT 26 | 27 | public: 28 | explicit MainWindow(QWidget *parent = 0); 29 | ~MainWindow(); 30 | 31 | }; 32 | 33 | #endif // MAINWINDOW_H 34 | -------------------------------------------------------------------------------- /mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | MainWindow 3 | 4 | 5 | 6 | 0 7 | 0 8 | 400 9 | 300 10 | 11 | 12 | 13 | MainWindow 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pcmantinker/Qt-Collapsible-Panel/835739a6dd0f74a401b230fe8bb8930d5279a522/open.png -------------------------------------------------------------------------------- /open_hover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pcmantinker/Qt-Collapsible-Panel/835739a6dd0f74a401b230fe8bb8930d5279a522/open_hover.png -------------------------------------------------------------------------------- /resources.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | closed.png 4 | closed_hover.png 5 | open.png 6 | open_hover.png 7 | 8 | 9 | --------------------------------------------------------------------------------