QT 状态栏的使用

状态栏显示的信息分3种
1. 一般信息,用QLabel 代表
2.  永久信息,文本会一直显示在状态栏的最右边。

3. 临时信息,指定信息现实的时间。时间到即信息消失

主窗体有一个默认的状态栏(同样有默认的菜单栏和工具栏), 
statusBar()就是获取默认的状态栏。然后添加东西即可。 
addWidget:一般是添加一个Label。//左侧 
showMessage:定时显示。 
addPermanentWidget:添加现实永久信息。//最右侧,

//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秒钟.

猜你喜欢

转载自blog.csdn.net/technologyleader/article/details/82185557