现在的位置: 首页 > 综合 > 正文

Qt 第六章 QScrollArea类给QWidget添加滚动条

2013年09月10日 ⁄ 综合 ⁄ 共 693字 ⁄ 字号 评论关闭

(1)滚动条窗体的构造

(2)widget设置背景色。



这个是本色

Dark是这样的:

只需要一个main函数就可以了。

#include"iconeditor.h"
#include<QScrollArea>
#include<QApplication>
int main(int argc,char *argv[])
{
    QApplication app(argc,argv);
    IconEditor *iconEditor=new IconEditor;
    iconEditor->setIconImage(QImage(":/images/mouse.png"));

    QScrollArea scrollArea;
    //iconEditor是要添加滚动条的窗口部件
    scrollArea.setWidget(iconEditor);
   //设置背景色的方法。
    scrollArea.viewport()->setBackgroundRole(QPalette::Light);
    scrollArea.viewport()->setAutoFillBackground(true);
   //设置窗体标题
    scrollArea.setWindowTitle(QObject::tr("Icon Editor"));

    scrollArea.show();
    return app.exec();
}

设置背景色的方法:

   //设置背景色的方法。
    scrollArea.viewport()->setBackgroundRole(QPalette::Light);
    scrollArea.viewport()->setAutoFillBackground(true);

抱歉!评论已关闭.