1.QTab的tab选项按钮的位置的调节
可以通过修改tabPosition的东西南北来实现
2.如何在关闭主窗口的同时来关闭子窗口
//主窗口
this->setAttribute(Qt::WA_QuitOnClose,true);
//所有子窗口
this->setAttribute(Qt::WA_QuitOnClose,false);
参考链接:1.父窗口关闭后子窗口仍然存在
3.多屏时控制子窗口显示在当前屏幕位置
QDesktopWidget *deskWgt = QApplication::desktop();
int curMonitor = deskWgt->screenNumber(this);
QRect screen = deskWgt->screenGeometry(curMonitor);
myUI.move(screen.x() + (screen.width() - myUI.width())/2, screen.y()+(screen.height() - myUI.height())/2);
4.QComoBox设置指定选项不可选并改变背景颜色
//disable the comobox item which is 111 or 222
QComboBox* myBox = new QComboBox();
myBox->addItem(tr("000"));
myBox->addItem(tr("111"));
myBox->addItem(tr("222"));
myBox->addItem(tr("333"));
myBox->addItem(tr("444"));
QVariant v(0);
myBox->setItemData(1, v, Qt::UserRole - 1);
myBox->setItemData(1, QColor(192,192,192), Qt::BackgroundColorRole);
myBox->setItemData(2, v, Qt::UserRole - 1);
myBox->setItemData(2, QColor(192,192,192), Qt::BackgroundColorRole);
myBox->setCurrentIndex(0);
5.QComoBox字体显示居中
QComboBox* box = new QComboBox(this);
QLineEdit* lineEdit = new QLineEdit(this);
QHBoxLayout* layoutBox = new QHBoxLayout;
layoutBox->setSpacing(0);
layoutBox->setMargin(0);
layoutBox->addWidget(lineEdit);
box->setLayout(layoutBox);
//box->setLineEdit(m_lineeidt); 不要使用这个,否则只有箭头区域可以选中
connect(box, SIGNAL(currentIndexChanged(const QString&)), lineEdit, SLOT(setText(const QString&)));
lineEdit->setReadOnly(true);
lineEdit->setEnabled(false);
lineEdit->setAlignment(Qt::AlignCenter);
QStringList itemss;
itemss << "offline" << "student" << "teacher" << "manager";
QListWidget *listWidget = new QListWidget(this);
for(int i = 0;i < itemss.count();++i)
{
QListWidgetItem *item = new QListWidgetItem(itemss.at(i));
item->setTextAlignment(Qt::AlignCenter);
listWidget->addItem(item);
}
box->setModel(listWidget->model());
box->setView(listWidget);
box->setStyleSheet("QComboBox {"
"color:black;"
"background-color:white;"
"outline:0px;"
"border:0px;"
"}"
"QComboBox::down-arrow{"
"right:3px;"
"image:url('subscriptLogin.png');"
"}"
"QComboBox:drop-down {"
"outline:0px;"
"border:0px;"
" }");
auto layout = new QHBoxLayout();
this->setLayout(layout);
layout->addWidget(box);