本文整理汇总了C++中QStandardItem::background方法的典型用法代码示例。如果您正苦于以下问题:C++ QStandardItem::background方法的具体用法?C++ QStandardItem::background怎么用?C++ QStandardItem::background使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QStandardItem
的用法示例。
在下文中一共展示了QStandardItem::background方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: clone
void tst_QStandardItem::clone()
{
QStandardItem item;
item.setText(QLatin1String("text"));
item.setToolTip(QLatin1String("toolTip"));
item.setStatusTip(QLatin1String("statusTip"));
item.setWhatsThis(QLatin1String("whatsThis"));
item.setSizeHint(QSize(64, 48));
item.setFont(QFont());
item.setTextAlignment(Qt::AlignLeft|Qt::AlignVCenter);
item.setBackground(QColor(Qt::blue));
item.setForeground(QColor(Qt::green));
item.setCheckState(Qt::PartiallyChecked);
item.setAccessibleText(QLatin1String("accessibleText"));
item.setAccessibleDescription(QLatin1String("accessibleDescription"));
item.setFlags(Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
QStandardItem *clone = item.clone();
QCOMPARE(clone->text(), item.text());
QCOMPARE(clone->toolTip(), item.toolTip());
QCOMPARE(clone->statusTip(), item.statusTip());
QCOMPARE(clone->whatsThis(), item.whatsThis());
QCOMPARE(clone->sizeHint(), item.sizeHint());
QCOMPARE(clone->font(), item.font());
QCOMPARE(clone->textAlignment(), item.textAlignment());
QCOMPARE(clone->background(), item.background());
QCOMPARE(clone->foreground(), item.foreground());
QCOMPARE(clone->checkState(), item.checkState());
QCOMPARE(clone->accessibleText(), item.accessibleText());
QCOMPARE(clone->accessibleDescription(), item.accessibleDescription());
QCOMPARE(clone->flags(), item.flags());
QVERIFY(!(*clone < item));
delete clone;
}
示例2: streamItem
void tst_QStandardItem::streamItem()
{
QStandardItem item;
item.setText(QLatin1String("text"));
item.setToolTip(QLatin1String("toolTip"));
item.setStatusTip(QLatin1String("statusTip"));
item.setWhatsThis(QLatin1String("whatsThis"));
item.setSizeHint(QSize(64, 48));
item.setFont(QFont());
item.setTextAlignment(Qt::AlignLeft|Qt::AlignVCenter);
item.setBackground(QColor(Qt::blue));
item.setForeground(QColor(Qt::green));
item.setCheckState(Qt::PartiallyChecked);
item.setAccessibleText(QLatin1String("accessibleText"));
item.setAccessibleDescription(QLatin1String("accessibleDescription"));
QByteArray ba;
{
QDataStream ds(&ba, QIODevice::WriteOnly);
ds << item;
}
{
QStandardItem streamedItem;
QDataStream ds(&ba, QIODevice::ReadOnly);
ds >> streamedItem;
QCOMPARE(streamedItem.text(), item.text());
QCOMPARE(streamedItem.toolTip(), item.toolTip());
QCOMPARE(streamedItem.statusTip(), item.statusTip());
QCOMPARE(streamedItem.whatsThis(), item.whatsThis());
QCOMPARE(streamedItem.sizeHint(), item.sizeHint());
QCOMPARE(streamedItem.font(), item.font());
QCOMPARE(streamedItem.textAlignment(), item.textAlignment());
QCOMPARE(streamedItem.background(), item.background());
QCOMPARE(streamedItem.foreground(), item.foreground());
QCOMPARE(streamedItem.checkState(), item.checkState());
QCOMPARE(streamedItem.accessibleText(), item.accessibleText());
QCOMPARE(streamedItem.accessibleDescription(), item.accessibleDescription());
QCOMPARE(streamedItem.flags(), item.flags());
}
}
示例3: getSetData
void tst_QStandardItem::getSetData()
{
QStandardItem item;
for (int x = 0; x < 2; ++x) {
for (int i = 1; i <= 2; ++i) {
QString text = QString("text %0").arg(i);
item.setText(text);
QCOMPARE(item.text(), text);
QPixmap pixmap(32, 32);
pixmap.fill((i == 1) ? Qt::red : Qt::green);
QIcon icon(pixmap);
item.setIcon(icon);
QCOMPARE(item.icon(), icon);
QString toolTip = QString("toolTip %0").arg(i);
item.setToolTip(toolTip);
QCOMPARE(item.toolTip(), toolTip);
QString statusTip = QString("statusTip %0").arg(i);
item.setStatusTip(statusTip);
QCOMPARE(item.statusTip(), statusTip);
QString whatsThis = QString("whatsThis %0").arg(i);
item.setWhatsThis(whatsThis);
QCOMPARE(item.whatsThis(), whatsThis);
QSize sizeHint(64*i, 48*i);
item.setSizeHint(sizeHint);
QCOMPARE(item.sizeHint(), sizeHint);
QFont font;
item.setFont(font);
QCOMPARE(item.font(), font);
Qt::Alignment textAlignment((i == 1)
? Qt::AlignLeft|Qt::AlignVCenter
: Qt::AlignRight);
item.setTextAlignment(textAlignment);
QCOMPARE(item.textAlignment(), textAlignment);
QColor backgroundColor((i == 1) ? Qt::blue : Qt::yellow);
item.setBackground(backgroundColor);
QCOMPARE(item.background().color(), backgroundColor);
QColor textColor((i == i) ? Qt::green : Qt::cyan);
item.setForeground(textColor);
QCOMPARE(item.foreground().color(), textColor);
Qt::CheckState checkState((i == 1) ? Qt::PartiallyChecked : Qt::Checked);
item.setCheckState(checkState);
QCOMPARE(item.checkState(), checkState);
QString accessibleText = QString("accessibleText %0").arg(i);
item.setAccessibleText(accessibleText);
QCOMPARE(item.accessibleText(), accessibleText);
QString accessibleDescription = QString("accessibleDescription %0").arg(i);
item.setAccessibleDescription(accessibleDescription);
QCOMPARE(item.accessibleDescription(), accessibleDescription);
QCOMPARE(item.text(), text);
QCOMPARE(item.icon(), icon);
QCOMPARE(item.toolTip(), toolTip);
QCOMPARE(item.statusTip(), statusTip);
QCOMPARE(item.whatsThis(), whatsThis);
QCOMPARE(item.sizeHint(), sizeHint);
QCOMPARE(item.font(), font);
QCOMPARE(item.textAlignment(), textAlignment);
QCOMPARE(item.background().color(), backgroundColor);
QCOMPARE(item.foreground().color(), textColor);
QCOMPARE(item.checkState(), checkState);
QCOMPARE(item.accessibleText(), accessibleText);
QCOMPARE(item.accessibleDescription(), accessibleDescription);
QCOMPARE(qvariant_cast<QString>(item.data(Qt::DisplayRole)), text);
QCOMPARE(qvariant_cast<QIcon>(item.data(Qt::DecorationRole)), icon);
QCOMPARE(qvariant_cast<QString>(item.data(Qt::ToolTipRole)), toolTip);
QCOMPARE(qvariant_cast<QString>(item.data(Qt::StatusTipRole)), statusTip);
QCOMPARE(qvariant_cast<QString>(item.data(Qt::WhatsThisRole)), whatsThis);
QCOMPARE(qvariant_cast<QSize>(item.data(Qt::SizeHintRole)), sizeHint);
QCOMPARE(qvariant_cast<QFont>(item.data(Qt::FontRole)), font);
QCOMPARE(qvariant_cast<int>(item.data(Qt::TextAlignmentRole)), int(textAlignment));
QCOMPARE(qvariant_cast<QBrush>(item.data(Qt::BackgroundColorRole)), QBrush(backgroundColor));
QCOMPARE(qvariant_cast<QBrush>(item.data(Qt::BackgroundRole)), QBrush(backgroundColor));
QCOMPARE(qvariant_cast<QBrush>(item.data(Qt::TextColorRole)), QBrush(textColor));
QCOMPARE(qvariant_cast<QBrush>(item.data(Qt::ForegroundRole)), QBrush(textColor));
QCOMPARE(qvariant_cast<int>(item.data(Qt::CheckStateRole)), int(checkState));
QCOMPARE(qvariant_cast<QString>(item.data(Qt::AccessibleTextRole)), accessibleText);
QCOMPARE(qvariant_cast<QString>(item.data(Qt::AccessibleDescriptionRole)), accessibleDescription);
item.setBackground(pixmap);
QCOMPARE(item.background().texture(), pixmap);
QCOMPARE(qvariant_cast<QBrush>(item.data(Qt::BackgroundRole)).texture(), pixmap);
}
item.setData(QVariant(), Qt::DisplayRole);
item.setData(QVariant(), Qt::DecorationRole);
item.setData(QVariant(), Qt::ToolTipRole);
item.setData(QVariant(), Qt::StatusTipRole);
item.setData(QVariant(), Qt::WhatsThisRole);
//.........这里部分代码省略.........
示例4: run
void ExcelControl::run(){
if(m_tableView == NULL || m_tableModel == NULL){
return;
}
int rowCount = m_tableModel->rowCount();
int colCount = m_tableModel->columnCount();
qDebug() << rowCount << colCount;
Document xlsx;
//单元格格式
Format cellFormat;
//颜色
QColor originColor = cellFormat.patternBackgroundColor();
//水平居中
cellFormat.setHorizontalAlignment(Format::AlignHCenter);
//垂直居中
cellFormat.setVerticalAlignment(Format::AlignVCenter);
//边框
cellFormat.setBorderStyle(Format::BorderThin);
//设置字体
cellFormat.setFont(QFont("微软雅黑"));
cellFormat.setFontSize(9);
//添加标题
cellFormat.setPatternBackgroundColor(QColor(0, 176, 200));
for(int i = 0;i < colCount;i++){
//获取标题单元格值
QString headerValue = m_tableModel->headerData(i, Qt::Horizontal).toString();
//字体加粗
cellFormat.setFontBold(true);
//给单元格设值并合并单元格
xlsx.write(1, i + 1, headerValue, cellFormat);
}
//字体不加粗
cellFormat.setFontBold(false);
//循环添加单元格内容
for(int i = 0;i < rowCount;i++){
for(int j = 0;j < colCount;j++){
QStandardItem *cellItem = m_tableModel->item(i, j);
if(cellItem != NULL){
//获取单元格值
QString cellValue = cellItem->text();
//获取单元格背景色
QColor cellBgColor = cellItem->background().color();
//给单元格设值并合并单元格
int rowSpan = m_tableView->rowSpan(i, j);
int colSpan = m_tableView->columnSpan(i, j);
cellFormat.setPatternBackgroundColor(cellBgColor);
xlsx.write(i + 2, j + 1, cellValue, cellFormat);
xlsx.mergeCells(CellRange(i + 2, j + 1, i + rowSpan + 1, j + colSpan), cellFormat);
}else{
//设置空值
int rowSpan = m_tableView->rowSpan(i, j);
int colSpan = m_tableView->columnSpan(i, j);
if(rowSpan == 1 && colSpan == 1){
cellFormat.setPatternBackgroundColor(originColor);
xlsx.write(i + 2, j + 1, "", cellFormat);
}
}
emit setProgressValue(i * colCount + j + 1, rowCount * colCount);
}
}
//保存excel
if(m_path.isEmpty()){
xlsx.save();
}else{
xlsx.saveAs(m_path);
}
//初始化
m_tableView = NULL;
m_tableModel = NULL;
//发送处理完成的信号
emit execute(true);
qDebug() << "excel done";
}