1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- #include "basedisplay_wgt.h"
- #include "ui_basedisplay_wgt.h"
- #include "attribute_wgt.h"
- BaseDisplay_wgt::BaseDisplay_wgt(QWidget *parent) :
- QWidget(parent),
- ui(new Ui::BaseDisplay_wgt)
- {
- ui->setupUi(this);
- Attribute_wgt *wgt = new Attribute_wgt;
- init_ui(wgt);
- }
- BaseDisplay_wgt::~BaseDisplay_wgt()
- {
- delete ui;
- if(m_tree_path_displaWgt!=nullptr){
- delete m_tree_path_displaWgt;
- }
- }
- void BaseDisplay_wgt::init_ui(QWidget *para)
- {
- para->setMinimumHeight(200);
- // this->setStyleSheet("background:rgb(199, 216, 255);");
- m_tree_path_displaWgt = new QWidget;
- m_tree_path_displaWgt->setMinimumWidth(100);
- QPushButton *file_btn = new QPushButton(QIcon("path/to/file_icon.png"), "File");
- file_btn->setMaximumWidth(100);
- QPushButton *up_btn = new QPushButton(QIcon("path/to/up_icon.png"), "↑");
- QPushButton *down_btn = new QPushButton(QIcon("path/to/down_icon.png"), "↓");
- QPushButton *left_btn = new QPushButton(QIcon("path/to/left_icon.png"), "<-");
- QPushButton *right_btn = new QPushButton(QIcon("path/to/right_icon.png"), "->");
- up_btn->setMaximumWidth(50);
- down_btn->setMaximumWidth(50);
- left_btn->setMaximumWidth(50);
- right_btn->setMaximumWidth(50);
- // 按钮创建布局
- QVBoxLayout *layout_btn = new QVBoxLayout;
- QHBoxLayout *layout1 = new QHBoxLayout;
- QHBoxLayout *layout2 = new QHBoxLayout;
- layout1->addWidget(file_btn);
- layout1->addWidget(up_btn);
- layout2->addWidget(left_btn);
- layout2->addWidget(right_btn);
- layout2->addWidget(down_btn);
- layout_btn->addLayout(layout1);
- layout_btn->addLayout(layout2);
- layout_btn->setSpacing(2);
- layout1->setSpacing(2);
- layout2->setSpacing(2);
- connect(file_btn, &QPushButton::clicked, this, &BaseDisplay_wgt::get_par);
- connect(left_btn, &QPushButton::clicked, this, &BaseDisplay_wgt::back);
- QHBoxLayout *layout_header = new QHBoxLayout;
- layout_header->addWidget(m_tree_path_displaWgt);
- layout_header->addLayout(layout_btn);
- wgt_layout = new QVBoxLayout; // 创建垂直布局↑↓
- wgt_layout->addLayout(layout_header);
- wgt_layout->addWidget(para);
- current_page = para;
- setLayout(wgt_layout);
- }
- void BaseDisplay_wgt::set_wgt(QWidget *w)
- {
- wgt_layout->removeWidget(current_page);
- wgt_layout->addWidget(w);
- }
- void BaseDisplay_wgt::get_par()
- {
- if(treeWidgetExample != nullptr)//点击file_btn,只会出现一个treewidget
- {
- delete treeWidgetExample;
- }
- treeWidgetExample = new InfoTree_wgt();
- treeWidgetExample->setWindowTitle("Tree Widget Example");
- set_wgt(treeWidgetExample);
- tree_page = treeWidgetExample;
- }
- void BaseDisplay_wgt::back()
- {
- wgt_layout->removeWidget(tree_page);
- //wgt_layout->addWidget(current_page);
- }
|