QT学习---状态栏的的提示和显示

1、状态栏的提示:

(1)创建Action对象;

(2)将Action对象添加到菜单或是工具条。

2、状态栏的显示主要分为三种:

(1)临时信息显示;

(2)一般信息显示;

(3)永久信息显示。


   
   
  1. /*1、菜单、工具条的状态栏提示*/
  2. //创建QAction对象
  3. openAction = new QAction("&Open",this);
  4. //设置快捷键
  5. openAction->setShortcut(QKeySequence::Open);
  6. //状态栏提示
  7. openAction->setStatusTip("Open a file");
  8. //加载图标
  9. openAction->setIcon(QIcon(":/QtStudy9/Resources/qt.PNG"));
  10. //connect(openAction,SIGNAL(triggered()),this,SLOT(open()));
  11. //把Action添加到菜单和工具条
  12. QMenu* mfile = menuBar()->addMenu("&File");
  13. mfile->addAction(openAction);
  14. QToolBar* tfile = addToolBar("&File");
  15. tfile->addAction(openAction);
  16. /*2、状态栏的临时信息、一般信息、永久信息的显示*/
  17. msgLable = new QLabel;
  18. msgLable->setMinimumSize(150,20/*msgLable->sizeHint()*/);
  19. msgLable->setAlignment(Qt::AlignHCenter);
  20. statusBar()->addWidget(msgLable);
  21. //statusBar()->showMessage("lin shi xin xi ",3000);//3s后关闭
  22. QStatusBar* bar = statusBar(); //获取状态栏
  23. QLabel* first_statusLabel = new QLabel; //新建标签
  24. first_statusLabel->setMinimumSize(150,20); //设置标签最小尺寸
  25. first_statusLabel->setFrameShape(QFrame::WinPanel); //设置标签形状
  26. first_statusLabel->setFrameShadow(QFrame::Sunken); //设置标签阴影
  27. QLabel* second_statusLabel = new QLabel;
  28. second_statusLabel->setMinimumSize(150,20);
  29. second_statusLabel->setFrameShape(QFrame::WinPanel);
  30. second_statusLabel->setFrameShadow(QFrame::Sunken);
  31. QLabel* third_statusLabel = new QLabel;
  32. QLabel* four_statusLabel = new QLabel;
  33. //显示一般信息栏
  34. bar->addWidget(first_statusLabel);
  35. bar->addWidget(second_statusLabel);
  36. //显示永久信息栏
  37. bar->addPermanentWidget(third_statusLabel);
  38. bar->insertPermanentWidget(3, four_statusLabel);
  39. first_statusLabel->setText(tr("status1")); //初始化内容
  40. second_statusLabel->setText(tr("status2"));
  41. third_statusLabel->setText("yong jiu xin xi");
  42. four_statusLabel->setText("four_statusLabel");
  43. //最后显示临时信息
  44. statusBar()->showMessage("lin shi xin xi ",3000);//3s后关闭

如果要消除状态栏中的竖线,添加语句:

statusBar()->setStyleSheet(QString("QStatusBar::item{border:0px}"));
   
   

如果要消除右下角控制点,添加语句:

statusBar()->setSizeGripEnabled(FALSE);
   
   

发布了8 篇原创文章 · 获赞 3 · 访问量 1932

猜你喜欢

转载自blog.csdn.net/weixin_44017727/article/details/97530579
今日推荐