Qt4之常用控件菜单,多文档

不用多说,粘上代码,你懂的。

1.菜单栏

    QMenu *layoutMenu = menuBar()->addMenu(tr("Layout"));
    
    QAction *arrange = new QAction(tr("Arrange Icons"),this);
    connect(arrange,SIGNAL(triggered()),workSpace,SLOT(arrangeIcons()));
    layoutMenu->addAction(arrange);
    
    QAction *tile = new QAction(tr("tile"),this);
    connect(tile,SIGNAL(triggered()),workSpace,SLOT(tile()));
    layoutMenu->addAction(tile);
    
    QAction *cascade = new QAction(tr("cascade"),this);
    connect(cascade,SIGNAL(triggered()),workSpace,SLOT(cascade()));
    layoutMenu->addAction(cascade);

注意:用加上#include <QtGui>

而且layoutMenu为第二级的。而menuBar()为最顶层的。

里面为layoutMenu->addAction(arrange),形式添加。


2.多文档

    workSpace = new QWorkspace;
    setCentralWidget(workSpace);  
    
    
    QMainWindow *window1 = new QMainWindow;
    window1->setWindowTitle(tr("window 1"));
    QTextEdit *edit1 = new QTextEdit;
    edit1->setText(tr("Window 1"));
    window1->setCentralWidget(edit1);
    
    QMainWindow *window2 = new QMainWindow;
    window2->setWindowTitle(tr("window 2"));
    QTextEdit *edit2 = new QTextEdit;
    edit2->setText(tr("Window 2"));
    window2->setCentralWidget(edit2);
    
    QMainWindow *window3 = new QMainWindow;
    window3->setWindowTitle(tr("window 3"));
    QTextEdit *edit3 = new QTextEdit;
    edit3->setText(tr("Window 3"));
    window3->setCentralWidget(edit3);
    
    workSpace->addWindow(window1);
    workSpace->addWindow(window2);
    workSpace->addWindow(window3);


这样要同一个窗体中有三个窗体。

它的布局方式有: tile,arrangeIcon,cacade三种。

对应有三种函数以提拱用tile(),arrageIcon(),cacade()。




你可能感兴趣的:(layout,文档,qt,Signal,icons)