1.标题栏设置为系统默认图标
m_pBtnClosed = new QPushButton;
m_pBtnClosed->setToolTip(tr("关闭"));
m_pBtnClosed->setIcon(QIcon(QApplication::style()->standardIcon(QStyle::SP_TitleBarCloseButton)));
m_pBtnMinimized = new QPushButton;
m_pBtnMinimized->setToolTip(tr("最小化"));
m_pBtnMinimized->setIcon(QIcon(QApplication::style()->standardIcon(QStyle::SP_TitleBarMinButton)));
m_pBtnMaximized = new QPushButton;
m_pBtnMaximized->setToolTip(tr("最大化"));
m_pBtnMaximized->setIcon(QIcon(QApplication::style()->standardIcon(QStyle::SP_TitleBarMaxButton)));
m_pBtnHelp = new QPushButton;
m_pBtnHelp->setToolTip(tr("帮助"));
m_pBtnHelp->setIcon(QIcon(QApplication::style()->standardIcon(QStyle::SP_MessageBoxQuestion)));
2.控件通过样式表设置背景时,不能为QWidget,否则不生效,只对其中部分子控件有效果
如setStyleSheet(“background-color:rgb(0,158,155)”); //控件改为QFrame,QDialog,设置可生效
3.设置控件最大化
QWidget w; w.showFullScreen();
4.槽函数识别发送信号对象
void CtrlPanelWgt::slot_NextStep()
{
QFrame *pWgt = qobject_cast<QFrame *>(sender());
if (m_spWgt1 == pWgt)
{
//发送对象为m_spWgt1;
}
else if (m_spWgt2 == pWgt)
{
//发送对象为m_spWgt2;
}
}
5.QStackedWidget使用需注意
使用insertWidget()插入控件时,index必须从0开始设置,否则setCurrentIndex()时会出现显示误差。
{
QStackedWidget *pStackWgt = new QStackedWidget(this);
QWidget *pWgt1 = new QWidget;
pStackWgt->setStyleSheet("background-color:red");
QWidget *pWgt2 = new QWidget;
pStackWgt->setStyleSheet("background-color:green");
pStackWgt->insertWidget(0, pWgt1);
pStackWgt->insertWidget(1, pWgt2);
pStackWgt->setCurrentIndex(0);
}