QT status bar, riveting components, core components

QT status bar, riveting components, core components

1. Status bar

  1. There is at most one status bar.
  2. Create status bar:QStatusBar *stBar = statusBar();
  3. Set to window:setStatusBar(stBar);
  4. Put the label control:QLabel *label1 = new QLabel("提示信息",this); stBar->addWidget(label1);
  5. Prompt information on the right:QLabel *label2 = new QLabel("右提示信息",this); stBar->addPermanentWidget(label2);

2. Riveting parts

  1. Riveted parts (floating windows): there can be multiple
  2. Create riveted parts:QDockWidget * dockWidget = new QDockWidget("浮动",this);
  3. Add to window:addDockWidget(Qt::BottomDockWidgetArea,dockWidget);
  4. Set the post-dock area to only allow up and down:dockWidget->setAllowedAreas(Qt::BottomDockWidgetArea|Qt::TopDockWidgetArea);

3. Core components

  • Center part: There can only be one center part
  • Create the center part:QTextEdit * edit = new QTextEdit(this);
  • Set up the center widget:setCentralWidget(edit);

4. Code examples

  • mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

class MainWindow : public QMainWindow
{
    
    
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
};
#endif // MAINWINDOW_H
  • mainwindow.cpp
#include "mainwindow.h"
#include <QStatusBar>
#include <QLabel>
#include <QDockWidget>
#include <QTextEdit>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    
    
    //重置窗口大小
    resize(600,400);
    //设置窗口标题
    setWindowTitle("状态栏、铆接部件、核心部件");
    //状态栏 最多有一个
    //创建状态栏
    QStatusBar *stBar = statusBar();
    //设置到窗口中
    setStatusBar(stBar);
    //放标签控件
    QLabel *label1 = new QLabel("提示信息",this);
    stBar->addWidget(label1);

    //右侧提示信息
    QLabel *label2 = new QLabel("右提示信息",this);
    stBar->addPermanentWidget(label2);

    //铆接部件(浮动窗口):可以有多个
    //创建铆接部件
    QDockWidget * dockWidget = new QDockWidget("浮动",this);
    //添加到窗口
    addDockWidget(Qt::BottomDockWidgetArea,dockWidget);

    //设置后期停靠区域,只允许上下
    dockWidget->setAllowedAreas(Qt::BottomDockWidgetArea|Qt::TopDockWidgetArea);
    //设置中心部件,只能有一个中心部件
    //创建中心部件
    QTextEdit * edit = new QTextEdit(this);
    //设置中心部件
    setCentralWidget(edit);

}
MainWindow::~MainWindow()
{
    
    
}
  • main.cpp
#include "mainwindow.h"

#include <QApplication>

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

5. Operation results

Insert image description here

Guess you like

Origin blog.csdn.net/qq_43762434/article/details/133171376