#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QHBoxLayout>
#include <QFileDialog>
#include <QButtonGroup>
#include <QStylePainter>
#include <QAbstractButton>
#include <QStyleFactory>
#include <QHeaderView>
#include <QStandardItemModel>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
QWidget *p = takeCentralWidget();
if (p){
delete p;
}
setDockNestingEnabled(true); //允许嵌套dockeidget
m_docks.append(ui->dockWidget_1); //记录所有dock的指针
m_docks.append(ui->dockWidget_2);
m_docks.append(ui->dockWidget_3);
m_docks.append(ui->dockWidget_4);
m_docks.append(ui->dockWidget_5);
m_docks.append(ui->dockWidget_6);
m_docks.append(ui->dockWidget_7);
m_docks.append(ui->dockWidget_8);
m_docks.append(ui->dockWidget_9);
m_docks.append(ui->dockWidget_10);
QProgressBar *pProgressBar3 = ui->progressBar;
pProgressBar3->setOrientation(Qt::Horizontal); // 水平方向
pProgressBar3->setMinimum(0); // 最小值R
pProgressBar3->setMaximum(4800); // 最大值
pProgressBar3->setValue(2000); // 当前进度
double dProgress = (pProgressBar3->value() - pProgressBar3->minimum()) * 100.0
/ (pProgressBar3->maximum() - pProgressBar3->minimum());
//fromLocal8Bit:它将一个本地编码的QByteArray对象转换为一个QString对象
//QString::number(dProgress, 'f', 1):显示fload类型,保留1位小数。将替换掉前方的 %1
pProgressBar3->setFormat(QString::fromLocal8Bit("Current is:%1%").arg(QString::number(dProgress, 'f', 1)));
pProgressBar3->setAlignment(Qt::AlignRight | Qt::AlignVCenter); // 对齐方式
connect(ui->Btn_InputSGY,&QPushButton::clicked,this,[=]{
//执行文件对话框
QFileDialog filedlg;
ui->Line_InputSGY->setText( filedlg.getOpenFileName(this,tr("Open File"),"./","Any files (*);;Image files (*.png *.jpg);;Text Files (*.txt)"));
if (ui->Line_InputSGY->text()!=""){
ui->lineEdit_8->setEnabled(true);
ui->lineEdit_9->setEnabled(true);
ui->lineEdit_10->setEnabled(true);
ui->lineEdit_11->setEnabled(true);
}
});
QButtonGroup *pBtnG = new QButtonGroup();
pBtnG->addButton(ui->Radio_2D);
pBtnG->addButton(ui->Radio_3D);
ui->Radio_2D->setChecked(true); //为radio组设置初选项
ui->tableWidget_3->setRowCount(13);
ui->tableWidget_3->setColumnCount(4);
ui->tableWidget_3->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
ui->tableWidget_3->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
ui->tableWidget_3->setStyleSheet("QHeaderView::section{" //设置表3样式
"border-top:0px solid #00FF00;"
"border-left:0px solid #00FF00;"
"border-right:0px solid #00FF00;"
"border-bottom: 0px solid #00FF00;"
"background-color:white;"
"padding:0px;"
"}"
);
ui->tableWidget_2->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); //自适应可伸缩
ui->tableWidget_2->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
ui->tableWidget->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
ui->tableWidget->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
setTableWidgetData();
splitDockWidget(ui->dockWidget_1,ui->dockWidget_2,Qt::Vertical);
splitDockWidget(ui->dockWidget_2,ui->dockWidget_3,Qt::Vertical);
splitDockWidget(ui->dockWidget_3,ui->dockWidget_4,Qt::Horizontal);
splitDockWidget(ui->dockWidget_4,ui->dockWidget_5,Qt::Horizontal);
splitDockWidget(ui->dockWidget_5,ui->dockWidget_6,Qt::Horizontal);
splitDockWidget(ui->dockWidget_3,ui->dockWidget_7,Qt::Vertical);
splitDockWidget(ui->dockWidget_4,ui->dockWidget_8,Qt::Vertical);
splitDockWidget(ui->dockWidget_5,ui->dockWidget_9,Qt::Vertical);
splitDockWidget(ui->dockWidget_6,ui->dockWidget_10,Qt::Vertical);
DeleteDockTitleLine();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::removeAllDock() // 会把所有dock隐藏
{
for (auto i: m_docks){
removeDockWidget(i);
}
}
/*
* 显示指定需要的dock
* index: 指定序号, 如果不指定, 则会显示所有
*/
void MainWindow::showDock(const QList<int> &index)
{
if ( index.isEmpty()){
for (int i = 0; i < m_docks.count(); ++i){
m_docks[i]->show();
}
}else{
foreach (int i, index) {
m_docks[i]->show();
}
}
}
void MainWindow::LayoutDockWidget()
{
}
void MainWindow::DeleteTitleLine(QDockWidget *pDock)
{
QWidget *pw1 = new QWidget();
delete pDock->titleBarWidget();
pDock->setTitleBarWidget(pw1);
}
void MainWindow::DeleteDockTitleLine()
{
DeleteTitleLine(ui->dockWidget_1);
DeleteTitleLine(ui->dockWidget_2);
DeleteTitleLine(ui->dockWidget_3);
DeleteTitleLine(ui->dockWidget_4);
DeleteTitleLine(ui->dockWidget_5);
DeleteTitleLine(ui->dockWidget_6);
DeleteTitleLine(ui->dockWidget_7);
DeleteTitleLine(ui->dockWidget_8);
DeleteTitleLine(ui->dockWidget_9);
DeleteTitleLine(ui->dockWidget_10);
}
void MainWindow::setTableWidgetData()
{
for ( int i= 0; i < ui->tableWidget_3->rowCount(); ++i){
ui->tableWidget_3->verticalHeaderItem(i)->setTextAlignment( Qt::AlignRight ); //列标题文字居中
QSpinBox *pSpinBox = new QSpinBox();
pSpinBox->setValue(0);
ui->tableWidget_3->setCellWidget(i,0,pSpinBox);
QComboBox *pCombox = new QComboBox();
pCombox->addItem(tr("32bit"));
pCombox->addItem(tr("16bit"));
ui->tableWidget_3->setCellWidget(i,1,pCombox);
QLineEdit *pLineEdit = new QLineEdit();
pLineEdit->setText("0");
ui->tableWidget_3->setCellWidget(i,2,pLineEdit);
QCheckBox * checkB = new QCheckBox(ui->tableWidget_3); //创建checkbox
QWidget *w = new QWidget(ui->tableWidget_3); //创建一个widget
QHBoxLayout *hLayout = new QHBoxLayout(); //创建布局
hLayout->addWidget(checkB); //添加checkbox
hLayout->setContentsMargins(0,0,0,0);
hLayout->setAlignment(checkB, Qt::AlignCenter); //居中
w->setLayout(hLayout); //设置widget的布局
ui->tableWidget_3->setCellWidget(i, 3, w); //将widget放到table中
}
for ( int i = 0; i < ui->tableWidget->columnCount();++i){
// 先这样,后期开启策略
if (i == 0){
QWidget *pWidget1 = new QWidget();
QVBoxLayout *pVB1 = new QVBoxLayout();
pVB1->setContentsMargins(0,0,0,0);
pWidget1->setLayout(pVB1);
QLabel *pLab1 = new QLabel("Trance number");
pLab1->setAlignment(Qt::AlignCenter);
pVB1->addWidget(pLab1);
ui->tableWidget->setCellWidget(0,i,pWidget1);
}
else
{
QLabel *pLab2 = new QLabel("trc seq\n in line\n 1 - 4");
pLab2->setAlignment(Qt::AlignCenter);
QComboBox *pCB2 = new QComboBox();
pCB2->addItem("Line Header");
QWidget *pWidget2 = new QWidget();
QVBoxLayout *pVB2 = new QVBoxLayout();
pVB2->setContentsMargins(0,0,0,0);
pVB2->addWidget(pLab2);
基于Qtcreator + Qt6.4.3环境的 DockWidget 使用方法
需积分: 0 136 浏览量
更新于2023-11-24
收藏 12KB ZIP 举报
主要是QDockwidget的使用,内部可以自由拖动,以及QDockewidget上各个控件的,适用于初学者,了解并学习。
里面有10个QDockWidget,每一个widget上面都有不同的控件以及布局方法供初学者进行参考。
J_admin
- 粉丝: 192
- 资源: 4
最新资源
- Matlab_多摄像机系统校准工具箱Matlab.zip
- Matlab_多尺度复合材料结构的并行拓扑优化.zip
- Matlab_二维卷积神经网络的Matlab代码.zip
- Matlab_二维数字图像相关Matlab软件.zip
- Matlab_反馈延迟网络fdn的Matlab工具箱.zip
- Matlab_二维自适应网格细化的Matlab高效实现.zip
- Matlab_非参数采样EfrosLeung纹理合成的Matlab实现.zip
- Matlab_方向统计和方向估计的Matlab库.zip
- Matlab_飞机动力学和控制库.zip
- Matlab_非负矩阵和张量分解的快速算法的Matlab实现.zip
- Matlab_非线性最小二乘的Matlab优化.zip
- Matlab_肺医学图像分析和可视化软件,Matlab.zip
- Matlab_分别实现1对模糊车牌图像进行清晰处理2对高斯模糊图像进行高斯平滑滤波处理3对椒盐噪声图像进行中值滤波处理.zip
- Matlab_该存储库使用优化的DWTDCT将消息嵌入到Image中.zip
- Matlab_该工具箱是PnP方法的Matlab集合,可以用来对算法进行基准测试.zip
- Matlab_高斯过程模型动态系统识别工具箱Matlab.zip