1 在MainWindow中
setAttribute(Qt::WA_DeleteOnClose);
在main()函数中如果
MainWindoiw win;
win.show();
当关闭程序时会报错,可以修改为
MainWindow * min = new MainWindow;
原因一个在堆上一个在栈上,setAttribute(Qt::WA_DeleteOnClose);之后会调用delete
(win)
2 在QTabWidget上可以设置小按钮在哪个角落
addTabButton=newQToolButton(this);
addTabButton->setDefaultAction(m_newTabAction);
addTabButton->setAutoRaise(true);
addTabButton->setToolButtonStyle(Qt::ToolButtonIconOnly);
setCornerWidget(addTabButton, Qt::TopRightCorner);addTabButton->show();这样可以在tabwidget的右上角显示按钮
3 QtabWidget 为每个标签设置关闭按钮
this->tabBar()->setTabsClosable(true);
实际上就是QTabBar的方法,设置之后当点击关闭按钮会发射信号
tabCloseRequeseted();
4 QTabBar里面设置
setContextMenuPolicy(Qt::CustomContextMenu);
This signal is emitted when the widget's contextMenuPolicy is Qt::CustomContextMenu,
and the user has requested a context menu on the widget. The position pos is the position of the context menu event that the widget receives. Normally this is in widget coordinates.设置 setContextMenuPolicy(Qt::CustomContextMenu) 会发射
:customContextMenuRequested ( const QPoint & pos ) [signal]
5 等待光标
QApplication::setOverrideCursor(Qt::WaitCursor);
QApplication::restoreOverrideCursor();
6使用 QTabWidget时候需要注意,如果要用addTab()函数,在TabBar上出现三角的小按钮,你需要在
setTabBar(m_tabBar);
setDocumentMode(true);如果在setTabBar前面用的setDocumentMode(true)会出现当添加一个tab的时候出现小三角,这里是用了自定义的TabBar7在QTabWidget里设置 setTabsClosable(true); 当点击每个tab上的关闭按钮的时候会发射
tabCloseRequested(); 信号
8 在QTabBar setMoveable(true) tabBar的标签可以移动,