QT滚动条功能开发
QT滚动条界面制作
如何实现在一个限定的窗口上动态的显示信息,可以采用滚动界面的形式进行。
如何进行布局
如图所示,灰色地方属于滚动界面区域,可以根据信息量的大小进行滚动扩展。
下面直接插入代码
为了防止违反公司关于代码规定,我这里只上传滚动条的功能开发,不上传相关业务功能开发。如果有疑问可以私聊我,谢谢。
头文件中添加:
#include
#include
private:
Ui::DlgStrangePolicyInput *ui;
QFrame pFrameUi;
QAxWidget webWidget;
QLabel *pLabelTitle; //放置滚动页面
QLabel *pLabelGetInfo;//显示滚动信息
QScrollArea *scrollArea;//滚动页面
QScrollBar *scrollBar;//滚动条
cpp文件中,添加:
初始化函数:
initScroll()
{
//定义主窗口的大小,450*290
pFrameUi = new QFrame(this);
pFrameUi->setFixedSize(450,290);
pFrameUi->move(1,1);
pFrameUi->setStyleSheet(“background-color:rgba(255,255,255,1);”);
pFrameUi->setVisible(true);
//放置滚动界面
pLabelTitle = new QLabel(pFrameUi);
pLabelTitle->setFixedSize(400,140);
pLabelTitle->move(25,100);
pLabelTitle->setStyleSheet(“font:15px;background:transparent;rgb(50,151,251)”);
//设置显示滚动界面大小
scrollArea = new QScrollArea(pLabelTitle);
scrollArea->setGeometry(0, 0, 390, 140);//左上长宽
scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
// scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);//隐藏竖向滚动条
scrollArea->setFrameShape(QFrame::NoFrame);
scrollArea->setStyleSheet( “width:8px; border-radius:2px;min-height:1;background:#FAFAFA”);
//设置实际滚动界面大小
widget = new QFrame(pLabelTitle);
widget->setContentsMargins(0, 0, 0, 0);
widget->setFixedSize(400, 25000);
widget->setStyleSheet( “background:#FAFAFA”);
//verticalScrollBar,设计滚动条的样式
scrollArea->verticalScrollBar()->setStyleSheet(“QScrollBar:vertical”
“{”
“width:6px;”
“background:rgba(0,0,0,0%);”
“margin:0px,0px,0px,0px;”
“padding-top:4px;”
“padding-bottom:4px;”
“}”
“QScrollBar::handle:vertical”
“{”
“width:6px;”
“background:rgba(0,0,0,25%);”
" border-radius:2px;"
“min-height:20;”
“}”
“QScrollBar::handle:vertical:hover”
“{”
“width:6px;”
“background:rgba(0,0,0,50%);”
" border-radius:2px;"
“min-height:20;”
“}”
“QScrollBar::add-line:vertical”
“{”
“height:9px;width:6px;”
“border-image:url(:/images/a/3.png);”
“subcontrol-position:bottom;”
“}”
“QScrollBar::sub-line:vertical”
“{”
“height:9px;width:6px;”
“border-image:url(:/images/a/1.png);”
“subcontrol-position:top;”
“}”
“QScrollBar::add-line:vertical:hover”
“{”
“height:9px;width:6px;”
“border-image:url(:/images/a/4.png);”
“subcontrol-position:bottom;”
“}”
“QScrollBar::sub-line:vertical:hover”
“{”
“height:9px;width:6px;”
“border-image:url(:/images/a/2.png);”
“subcontrol-position:top;”
“}”
);
scrollArea->setWidget(widget);
widget->setObjectName(“we”);
//pLabelGetInfo,显示信息界面样式
pLabelGetInfo = new QLabel(widget);
pLabelGetInfo->move(0,10);
pLabelGetInfo->setStyleSheet(“font:12px;background:transparent;”);
}
本人csdn的第一篇技术文档,为了提高自己的开发技能,希望大家多多指点和批评,共同学习
[1]: http://meta.math.stackexchange.com/questions/5020/mathjax-basic-tutorial-and-quick-reference
[2]: https://mermaidjs.github.io/
[3]: https://mermaidjs.github.io/
[4]: http://adrai.github.io/flowchart.js/