Coder Social home page Coder Social logo

shadowsith / qdocker Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 1.0 24 KB

Small qt widget docker class to dock one ui element to another.

License: GNU Lesser General Public License v3.0

C++ 88.97% QMake 8.93% C 2.09%
qt5 qt5-widgets lgplv3 ui-library cpp-library

qdocker's Introduction

QDocker

AppVeyor Status


QDocker is a small qt library to dock a widget object to another 'anchor' widget object.

  • Uses only QWidget class
  • Available for all classes which inherits form QWidget
  • Can be used for dynamic allocated and stack objects

Features

Docking all UI elements which are inheriting form QWidget to each other:

  • Above
  • Below
  • Left
  • Right

Align the widgets in connection with docking to the following positions:

On docking below/above

  • Horizontal:
    • Left
    • Right
    • Center

On docking left/right

  • Vertical:
    • Top
    • Bottom
    • Center

Check if the widgets have the same horizontal or vertical state

Installation

Add qdocker.h and qdocker.cpp to your project and #include "qdocker.h"
I also recommend to add the project's license to your source code to avoid copyright problems.

Usage

QDocker qd; // create default QDocker object with docking distance of 20 
QDocker qd(40); // QDocker object has default distance of 40
qd.getDistance(); // get the current distance
qd.setDistance(); // set another default distance

qd.dockBelow(widget1, widget2, qd.AlignLeft); // docks widget1 left-aligned below widget2  
qd.dockAbove(widget1, widget2, qd.AlignRight); // docks widget1 right-aligned above widget2  

qd.dockLeft(widget1, widget2, qd.AlignTop); // docks widget1 left from widget2 (top edge)
qd.dockRight(widget1, widget2, qd.AlignBottom, 30); // docks widget1 right from widget2 (lower edge) with distance 30

// check if the widgets start at the same horizontal X-Position (left aligned)
bool status = qd.isDocked(widget1, widget2, qd.AlignLeft); 

TODO

  • Adding docking on parent-widget Corner

Example (not implmented yet):

QDocker qd;

// adds the item on the top left corner of its parent widget
qd.dockCorner(ui->itm, Corner.TL(5, 5));

Example

#include "testwindow.h"
#include "ui_testwindow.h"
#include "qdocker.h"
#include <QLineEdit>
#include <QLabel>
#include <QMessageBox>
#include <QTextEdit>
#include <QCheckBox>

TestWindow::TestWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::TestWindow)
{
    ui->setupUi(this);
    this->resize(400,400);
    QDocker qd; // QDocker with standard distance of 20

    QLineEdit* le1 = new QLineEdit(ui->centralWidget);
    le1->move(20,30);
    le1->resize(150, 20);

    QLabel* desc = new QLabel(ui->centralWidget);
    desc->resize(200,20);
    desc->setText("UI setup with QDocker:");
    qd.dockAbove(desc, le1, qd.AlignLeft, 10);

    QLineEdit* le2 = new QLineEdit(ui->centralWidget);
    le2->resize(100, 20);
    qd.dockBelow(le2, le1, qd.AlignLeft);

    QLineEdit* le3 = new QLineEdit(ui->centralWidget);
    le3->resize(150,20);
    qd.dockRight(le3, le1, qd.AlignTop);

    QTextEdit* te = new QTextEdit(ui->centralWidget);
    te->resize(200, 200);
    qd.setDistance(40);
    qd.dockBelow(te, le2, qd.AlignLeft);

    QLabel *lbl = new QLabel(ui->centralWidget);
    lbl->resize(100, 20);
    lbl->setText("Example:");
    lbl->setAlignment(Qt::AlignRight);
    qd.setDistance(20);
    qd.dockRight(lbl, te, qd.AlignTop);

    QLineEdit* le4 = new QLineEdit(ui->centralWidget);
    le4->resize(100, 20);
    qd.dockBelow(le4, lbl, qd.AlignRight);

    QCheckBox* cb = new QCheckBox(ui->centralWidget);
    cb->setText("Checkbox:");
    cb->resize(100,20);
    qd.dockRight(cb, te, qd.AlignVCenter);
}

Issues

  • If a new instance of a widget object has not get a value for width/height QDocker has strange behaviors

Why I have not used Qt::AlignmentFlag

  • to much values that I have not used
  • HorizontalPos and VerticalPos in QDocker class capsules it better for the situtation
  • incorrect input can be checked by IDE linters
  • to keep the Qt coding standards as good as possible the alignment flags have the same name as in Qt::AlignmentFlag

License

LGPL

For commecial use and incompatible open-source licenses I recommend to use the library only with dynamic linking.

qdocker's People

Contributors

shadowsith avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

qt-widgets

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.