Home About

How to make a side panel using Qt Widgets



Qt provides a huge amount of widgets, making it very easy and tempting to stuff the UI with them to enable features and maximize customization.

But that comes at the cost of cramming the interface, rendering it almost unusable and overwhelming.

In comes MSidePanel, a simple and customizable side panel widget that acts as a drawer:

Expand GIF

But better, because MSidePanel can hide completely, including its handle.


Components:

1. A Tools Container

This is the drawer box, where you add the widgets to the side panel. Its simplicity allows for any layout, offering a blank canvas to be designed.

2. A Handle Widget

MSidePanel uses a QPushButton as the handle widget, providing the essential functionality to open and close the side panel. Its visibility can be adjusted to accommodate as many use cases as possible, especially the ones needing a clean and unobstructed interface when the panel is not in use.



Example Usage:


#include "msidepanel.h"
#include <QApplication>
#include <QTableWidget>

void fillSidePanel(MSidePanel *sidePanel)
{
    QTableWidget *t = new QTableWidget;
    t->setRowCount(5);
    t->setColumnCount(5);
    sidePanel->addWidget(t);
    sidePanel->addWidget(new QPushButton());
    sidePanel->addWidget(new QPushButton());
    sidePanel->addWidget(new QPushButton());
}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QWidget w;

    MSidePanel topSidePanel(MSidePanel::Top, &w);
    MSidePanel bottomSidePanel(MSidePanel::Bottom, &w);
    MSidePanel rightSidePanel(MSidePanel::Right, &w);
    MSidePanel leftSidePanel(MSidePanel::Left, &w);

    fillSidePanel(&topSidePanel);
    fillSidePanel(&bottomSidePanel);
    fillSidePanel(&rightSidePanel);
    fillSidePanel(&leftSidePanel);

    w.show();

    return a.exec();
}

And here it is:
Expand GIF

Customizing MSidePanel



MSidePanel is simple in usage, yet it offers a lot of options and possibilities.
You can find it in my BitBucket repository, experience with it and see if you can improve it!