zoukankan      html  css  js  c++  java
  • QStatusBar的用法

       QStatusBa,状态栏是位于主窗口的最下方,提供一个显示工具提示等信息的地方。QMainWindow类里面就有一个statusBar()函数,用于实现状态栏的调用。以下例子都在QMainWindow的窗口前提下运行。

      1.状态栏添加 QLabel

      QLabel *msgLabel = new QLabel;

      msgLabel->setStyleSheet(" QLabel{ color: red }");

      // 设置字体颜色

      msgLabel->setText("Ready :");

      statusBar()->addWidget(msgLabel);

      

     2.状态栏下直接显示信息 showMessage

      statusBar()->setStyleSheet("color:green");  // 设置字体颜色

      statusBar()->showMessage(tr("Ready"));

      注意: 状态栏有showMessage和其他控件同时显示的时候,他们之间会有覆盖现象。

     3.多个控件一起放在状态栏

     QLineEdit *lineEdit = new QLineEdit;

     lineEdit->setStyleSheet(" QLineEdit{ color: green }");

     lineEdit->setText("to ");

     statusBar()->addWidget(lineEdit);//增加一个QLineEdit

     QLabel *myLabel = new QLabel;

     myLabel->setStyleSheet(" QLabel{ color: green }");

     myLabel->setText("somewhere");

     statusBar()->addWidget(myLabel); // 增加一个QLabel

     .....

     还可以增加其他很多不同的控件。

     

     4.删除指定的控件

     statusBar()->removeWidget(myLabel); 

       5.  常用属性的设置

       QTextEdit *toolsTip = new QTextEdit;

       toolsTip->setMinimumSize(500, 25);
       toolsTip->setMaximumHeight(20); // 最大高度20
       toolsTip->setReadOnly(true); // 只读
       toolsTip->setFrameShape(QFrame::NoFrame); // 无边框
       toolsTip->setFrameStyle(QFrame::NoFrame); // 第二种方法 无表框

       toolsTip->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); // 去掉滚动条

       toolsTip->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); // 增加滚动条
       statusBar()->addWidget(toolsTip);

     

  • 相关阅读:
    C#磁吸屏幕窗体类库
    准备
    我写的诗
    How to turn off a laptop keyboard
    How to tell which commit a tag points to in Git?
    Why should I care about lightweight vs. annotated tags?
    How to get rid of “would clobber existing tag”
    Facebook, Google and Twitter threaten to leave Hong Kong over privacy law changes
    The need for legislative reform on secrecy orders
    Can a foreign key be NULL and/or duplicate?
  • 原文地址:https://www.cnblogs.com/toby-zhang/p/5729629.html
Copyright © 2011-2022 走看看