如何在Qt中的QDockWidget中设置状态栏上的文本并启用关闭按钮?

发布于 2025-01-17 07:34:39 字数 1037 浏览 5 评论 0原文

我里面有一个 QDockWidget 和 QToolBar 。我尝试为 QdockWidget 设置 StatusBar 但无法设置。
每个 QDockWidget 都有默认的关闭按钮(右上角),但我的 DockWidget 没有它?
为什么 ?以及如何把它带回来?

myClass::myClass(QWidget* parent) :
    QDockWidget(parent)

{
   hide();
   QWidget* newWidget = new QWidget();
   QBoxLayout* tLayout = new QBoxLayout(QBoxLayout::TopToBottom,newWidget );
   tLayout->setContentsMargins(0, 0, 0, 0);

   QLabel *label = new QLabel("My Window",this);

   this->setTitleBarWidget(label);
   tbar = new QToolBar;
   tbar->setIconSize(QSize(35,35));
   tbar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
   tLayout->addWidget(tbar,0,Qt::AlignTop);
   QGraphicsScene* scene = new QGraphicsScene(this);
   QGraphicsView* view = new QGraphicsView(this);
   view->setScene(scene);
   tLayout->addWidget(view);
   newWidget ->setLayout(tLayout);

   bar = new QStatusBar();
   bar->showMessage(tr("Ready"));
   this->setWidget(bar);

   setWidget(newWidget);
}     
 

如何设置状态栏?并启用关闭按钮?

I have a QDockWidget and QToolBar in it. I tried to set StatusBar for QdockWidget but it could not be set.
Every QDockWidget has default close button (top most right corner) but my DockWidget does not have it ?
Why ? And how to bring it back ?

myClass::myClass(QWidget* parent) :
    QDockWidget(parent)

{
   hide();
   QWidget* newWidget = new QWidget();
   QBoxLayout* tLayout = new QBoxLayout(QBoxLayout::TopToBottom,newWidget );
   tLayout->setContentsMargins(0, 0, 0, 0);

   QLabel *label = new QLabel("My Window",this);

   this->setTitleBarWidget(label);
   tbar = new QToolBar;
   tbar->setIconSize(QSize(35,35));
   tbar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
   tLayout->addWidget(tbar,0,Qt::AlignTop);
   QGraphicsScene* scene = new QGraphicsScene(this);
   QGraphicsView* view = new QGraphicsView(this);
   view->setScene(scene);
   tLayout->addWidget(view);
   newWidget ->setLayout(tLayout);

   bar = new QStatusBar();
   bar->showMessage(tr("Ready"));
   this->setWidget(bar);

   setWidget(newWidget);
}     
 

How to set status bar ? and enable close button ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

把人绕傻吧 2025-01-24 07:34:39
// change to:
QWidget* newWidget = new QWidget(this);
...
tbar = new QToolBar(this);
...
bar = new QStatusBar(this);

// replace:
this->setWidget(bar);
// with:
tLayout->addWidget(bar);

// replace:
this->setTitleBarWidget(label);
// with:
titleBarWidget()->layout()->insertItem(0, label);
// change to:
QWidget* newWidget = new QWidget(this);
...
tbar = new QToolBar(this);
...
bar = new QStatusBar(this);

// replace:
this->setWidget(bar);
// with:
tLayout->addWidget(bar);

// replace:
this->setTitleBarWidget(label);
// with:
titleBarWidget()->layout()->insertItem(0, label);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文