QT splitter widget?

Greetings to all

Is there any widget to separate two QWidgets, as well as full focus on one widget. As shown in the following figure? alt text

Thanks in advance, umanga

+3
source share
1 answer

How about QSplitter ?

QWidget 1 , for exmaple, QListView. QWidget 2 is a combination QWidget(the left part is simple QPushButtonwith the inscription show / hide caption, and the right part is for other widgets) ... All you need to do is hide your QWidget2 when the user clicked on QPushButton...

If you need an example, I can post it.


Update

main.cpp

#include "splitter.h"
#include <QtGui/QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    splitter w;
    w.show();
    return a.exec();
}

splitter.h

#ifndef SPLITTER_H
#define SPLITTER_H

#include <QtGui/QDialog>

class splitter : public QDialog
{
    Q_OBJECT;

    QWidget*        widget1;
    QWidget*        widget2;

    QPushButton*    button;

public:
    splitter(QWidget *parent = 0, Qt::WFlags flags = 0);
    ~splitter();

private slots:
    void    showHide(void);
};

#endif // SPLITTER_H

splitter.cpp

#include <QtGui>

#include "splitter.h"

splitter::splitter(QWidget *parent, Qt::WFlags flags)
    : QDialog(parent, flags)
{
    QApplication::setStyle("plastique");

    QListView*      listView = new QListView;
    QTableView*     tableView = new QTableView;
    button = new QPushButton("Hide >");

    widget1 = new QWidget;
    QHBoxLayout*    w1Layout = new QHBoxLayout;
    w1Layout->addWidget(listView);
    w1Layout->addWidget(button);
    widget1->setLayout(w1Layout);

    widget2 = new QWidget;
    QHBoxLayout*    w2Layout = new QHBoxLayout; 
    w2Layout->addWidget(tableView);
    widget2->setLayout(w2Layout);

    QSplitter *mainSplitter = new QSplitter(this);
    mainSplitter->addWidget(widget1);
    mainSplitter->addWidget(widget2);

    connect(button, SIGNAL(clicked()), this, SLOT(showHide()));

    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addWidget(mainSplitter);

    setLayout(mainLayout);
}
splitter::~splitter()
{}
void splitter::showHide(void)
{
    if (widget2->isVisible())
    {   // hide     
        widget2->setVisible(false);
        button->setText("< Show");
    }
    else
    {   // show     
        widget2->setVisible(true);
        button->setText("Hide >");
    }
}
+6

Source: https://habr.com/ru/post/1768573/


All Articles