0
而使用Qt 5的QVariant ::的QVariant(QT :: BrushStyle)是私有的
styleComboBox = new QComboBox;
typedef QPair<QString, Qt::BrushStyle> BrushPair;
foreach (const BrushPair &pair, QList<BrushPair>()
<< qMakePair(tr("No Brush"), Qt::NoBrush)
<< qMakePair(tr("Solid"), Qt::SolidPattern)
<< qMakePair(tr("Dense #1"), Qt::Dense1Pattern)
<< qMakePair(tr("Dense #2"), Qt::Dense2Pattern)
<< qMakePair(tr("Dense #3"), Qt::Dense3Pattern)
<< qMakePair(tr("Dense #4"), Qt::Dense4Pattern)
<< qMakePair(tr("Dense #5"), Qt::Dense5Pattern)
<< qMakePair(tr("Dense #6"), Qt::Dense6Pattern)
<< qMakePair(tr("Horizontal"), Qt::HorPattern)
<< qMakePair(tr("Vertical"), Qt::VerPattern)
<< qMakePair(tr("Cross"), Qt::CrossPattern)
<< qMakePair(tr("Diagonal /"), Qt::BDiagPattern)
<< qMakePair(tr("Diagonal \\"), Qt::FDiagPattern)
<< qMakePair(tr("Diagonal Cross"), Qt::DiagCrossPattern))
styleComboBox->addItem(pair.first, pair.second);
該錯誤消息編譯下面的代碼段產生誤差低於:
C:\Qt\Qt5.2.1\5.2.1\mingw48_32\include\QtCore\qvariant.h:481: error: 'QVariant::QVariant(Qt::BrushStyle)' is private
QVariant(Qt::BrushStyle) Q_DECL_EQ_DELETE;
^
SO怎麼辦我克服了它?
感謝。然而,我通過將addItem的第二個成員轉換爲int來解決它:styleComboBox-> addItem(brushSwatch(pair.second),pair.first,static_cast(pair.second)); –
user1659459
我不建議在這裏使用static_cast來int。通過這樣做,你會失去與QBrush相關的任何內容 – tinkertime