zoukankan      html  css  js  c++  java
  • [转]Qt状态栏(statusbar)的使用

    状态栏显示的信息分3种
    1. 一般信息,用QLabel 代表
    2. 永久信息,文本会一直显示在状态栏的最右边。
    3. 临时信息,指定信息现实的时间。时间到即信息消失

    QLabel *locationLabel;
    locationLabel = new QLabel("July");
    locationLabel->setAlignment(Qt::AlignCenter);
    locationLabel->setMinimumSize(locationLabel->sizeHint());
    
    QLabel *aixLabel;
    aixLabel = new QLabel(""CTRL + H" for help");
    
    //Optional
    statusBar()->setStyleSheet(QString("QStatusBar::item{border: 0px}")); // 设置不显示label的边框
    statusBar()->setSizeGripEnabled(false); //设置是否显示右边的大小控制点
    statusBar()->addWidget(locationLabel);
    statusBar()->addWidget(aixLabel, 1);
    
    QLabel *per1 = new QLabel("Ready1", this);
    QLabel *per2 = new QLabel("Ready2", this);
    QLabel *per3 = new QLabel("Ready3", this);
    statusBar()->addPermanentWidget(per1); //现实永久信息
    statusBar()->addPermanentWidget(per2);
    statusBar()->insertPermanentWidget(2, per3);
    
    statusBar()->showMessage("Status is here...", 3000); // 显示临时信息,时间3秒钟.
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
    //    QLabel *normal=new QLabel("正常信息",this);
    //    ui->statusBar->addWidget(normal);//显示正常信息
    
        ui->statusBar->setSizeGripEnabled(false);//去掉状态栏右下角的三角
    
        ui->statusBar->showMessage(tr("临时信息!"),2000);//显示临时信息2000ms 前面的正常信息被覆盖 当去掉后一项时,会一直显示
    
        QLabel *permanent=new QLabel(this);
        permanent->setFrameStyle(QFrame::Box|QFrame::Sunken);
        permanent->setText(tr("<a href="http://tengweitw.ueuo.com">永久信息</a>"));
        permanent->setOpenExternalLinks(true);//设置可以打开网站链接
        ui->statusBar->addPermanentWidget(permanent);//显示永久信息

    参考:

    1. http://blog.csdn.net/tengweitw/article/details/22511521
    2. http://blog.csdn.net/u010002704/article/details/39060437
  • 相关阅读:
    Python基础06 循环
    Python基础04 运算
    Python基础02 基本数据类型
    Python基础03 序列
    C++ ------ 引用
    C++ ------ 互斥锁、原子操作的性能测试
    Qt ------ 断开某对信号与槽的connect
    5种网络通信设计模型(也称IO模型)
    Qt ------ 主事件循环与 QEventLoop
    Qt ------ 再论事件循环
  • 原文地址:https://www.cnblogs.com/rainbow70626/p/10344402.html
Copyright © 2011-2022 走看看