Qt之停靠窗体QDockWidget类


 代码

FirstQT::FirstQT(QWidget *parent)
	: QMainWindow(parent)
{
	ui.setupUi(this);
	//设置主窗口   
	setWindowTitle(tr("DockWindwos"));  
	QTextEdit *te=new QTextEdit(this);  
	te->setText(tr("Main Window"));  
	te->setAlignment(Qt::AlignCenter);  
	setCentralWidget(te);  
	//设置停靠窗口1   
	QDockWidget *dock=new QDockWidget(tr("DockWindow1"),this);  
	dock->setFeatures(QDockWidget::DockWidgetMovable);  
	dock->setAllowedAreas(Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea);  
	QTextEdit *te1=new QTextEdit();  
	te1->setText(tr("Window1,The dock widget can be moved between docks by the user"));  
	dock->setWidget(te1);  
	addDockWidget(Qt::RightDockWidgetArea,dock);  
	//设置停靠窗口2   
	dock=new QDockWidget(tr("DockWindow2"),this);  
	dock->setFeatures(QDockWidget::DockWidgetClosable|QDockWidget::DockWidgetFloatable);  
	QTextEdit *te2=new QTextEdit();  
	te2->setText(tr("Window2,The dock widget can floated and can be closed"));  
	dock->setWidget(te2);  
	addDockWidget(Qt::RightDockWidgetArea,dock);  
	//设置停靠窗口3   
	dock=new QDockWidget(tr("DockWindow3"),this);  
	dock->setFeatures(QDockWidget::AllDockWidgetFeatures);  
	QTextEdit *te3=new QTextEdit();  
	te3->setText(tr("Window3,The dock widget can be closed, moved and floated"));  
	dock->setWidget(te3);  
	addDockWidget(Qt::RightDockWidgetArea,dock); 
}

 效果



 

使用到的函数:

features : DockWidgetFeatures

This property holds whether the dock widget is movable, closable, and floatable.

By default, this property is set to a combination of DockWidgetClosable, DockWidgetMovable and DockWidgetFloatable.

Access functions:

DockWidgetFeaturesfeatures() const
voidsetFeatures(DockWidgetFeatures features)

Notifier signal:

void featuresChanged(QDockWidget::DockWidgetFeatures features)

其中,DockWidgetFeature为:

enum QDockWidget::DockWidgetFeature
flags QDockWidget::DockWidgetFeatures

ConstantValueDescription
QDockWidget::DockWidgetClosable0x01The dock widget can be closed. On some systems the dock widget always has a close button when it's floating (for example on MacOS 10.5).
QDockWidget::DockWidgetMovable0x02The dock widget can be moved between docks by the user.
QDockWidget::DockWidgetFloatable0x04The dock widget can be detached from the main window, and floated as an independent window.
QDockWidget::DockWidgetVerticalTitleBar0x08The dock widget displays a vertical title bar on its left side. This can be used to increase the amount of vertical space in a QMainWindow.
QDockWidget::AllDockWidgetFeaturesDockWidgetClosable | DockWidgetMovable | DockWidgetFloatable(Deprecated) The dock widget can be closed, moved, and floated. Since new features might be added in future releases, the look and behavior of dock widgets might change if you use this flag. Please specify individual flags instead.
QDockWidget::NoDockWidgetFeatures0x00The dock widget cannot be closed, moved, or floated.

allowedAreas : Qt::DockWidgetAreas

This property holds areas where the dock widget may be placed.

The default is Qt::AllDockWidgetAreas.

Access functions:

Qt::DockWidgetAreas allowedAreas() const
void setAllowedAreas(Qt::DockWidgetAreas areas)

Notifier signal:

void allowedAreasChanged(Qt::DockWidgetAreas allowedAreas)

enum Qt::DockWidgetArea
flags Qt::DockWidgetAreas

ConstantValue
Qt::LeftDockWidgetArea0x1
Qt::RightDockWidgetArea0x2
Qt::TopDockWidgetArea0x4
Qt::BottomDockWidgetArea0x8
Qt::AllDockWidgetAreasDockWidgetArea_Mask
Qt::NoDockWidgetArea0



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值