在 paintEvent(QPaintEvent *event) 事件中加入以下代码段有效。 在Win10中(linux不行)还可以加在resizeEvent(QResizeEvent *event)中也有效
if(this->menuBar())
{
this->menuBar()->move(1,m_title->height()+1);
}
this->menuBar()->setFixedWidth(this->width()-2);
想自定义标题栏,
setWindowFlags(Qt::FramelessWindowHint|Qt::X11BypassWindowManagerHint); //无边框
然后有布局,给布局一个margintop。没有布局就遍历控件下移
void SuwellMainWindow::SearchControl(QWidget *wi)
{
QObjectList list =wi->children();//所有子节点
QWidget *b;
if(wi->layout())
{
wi->setContentsMargins(wi->contentsMargins().left()+1,
wi->contentsMargins().top()+1+m_title->height(),
wi->contentsMargins().right()+1,
wi->contentsMargins().bottom()+1);
this->resize(wi->width(),wi->height()+m_title->height());
// return;
}
for(int i=0;i<list.size();i++)
{
b = qobject_cast<QWidget*>(list[i]);
if(b && b!=m_title)
{
m_WidgetList.append(b);
b->setGeometry(b->x(),b->y()+m_title->height(),b->width(),b->height());
}
}
this->resize(wi->width(),wi->height()+m_title->height());
if(MIN_WIDTH<0 && MIN_HEIGHT<0)
{
MIN_HEIGHT= this->height();
MIN_WIDTH = this->width();
this->setMinimumSize(MIN_WIDTH,MIN_HEIGHT);
this->setMaximumSize(MAX_WIDTH,MAX_HEIGHT);
}
}