#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
};
#endif // MAINWINDOW_H
#include "mainwindow.h"
#include
#include
#include
#include
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { setWindowTitle(tr("DockWidget")); QTextEdit *text = new QTextEdit(this); text->setText(tr("Main Window")); text->setAlignment(Qt::AlignCenter);//水平中心对其 setCentralWidget(text);//主窗体的中央窗体 //创建一个停靠窗体 QDockWidget *dock = new QDockWidget(tr("DockWidget1"),this); dock->setFeatures(QDockWidget::DockWidgetMovable); //设置停靠窗体可以移动 //指定停靠区域 dock->setAllowedAreas(Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea); QTextEdit *text1 = new QTextEdit(); text1->setText(tr("这是一个可以移动的停靠窗体")); dock->setWidget(text1); //将停靠窗体加入到指定区域 addDockWidget(Qt::RightDockWidgetArea,dock); //创建第二个停靠窗口 dock = new QDockWidget(tr("Dock 2"),this); dock->setFeatures(QDockWidget::DockWidgetClosable|QDockWidget::DockWidgetFloatable); QCalendarWidget *time = new QCalendarWidget(this); dock->setWidget(time); addDockWidget(Qt::RightDockWidgetArea,dock); //停靠窗口三 dock = new QDockWidget(tr("停靠窗口3"),this); dock->setFeatures(QDockWidget::AllDockWidgetFeatures); QTimeEdit *t = new QTimeEdit(this); QTime c = QTime::currentTime(); //QTime time1 = QTime::fromString(c); t->setTime(c); dock->setWidget(t); addDockWidget(Qt::RightDockWidgetArea,dock); } MainWindow::~MainWindow() { } #include "mainwindow.h" #include
int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); }
QDockWidget
最新推荐文章于 2020-08-17 14:27:49 发布