デリゲート内に QComboBox を描画したいのですが、コンボ ボックス内に表示される初期テキストを描画する方法がわかりません。
ドキュメントには、QStyleOptionComboBox.currentText
「コンボ ボックスの現在の項目のテキスト」が保持されていると記載されています。ただし、変数を設定しても効果はありません。
これは私のコードです:
void MyDelegate::paint(QPainter *painter,
const QStyleOptionViewItem& option,
const QModelIndex& index) const
{
QStyleOptionComboBox comboBoxOption;
comboBoxOption.rect = option.rect;
comboBoxOption.state = option.state;
comboBoxOption.state |= QStyle::State_Enabled;
comboBoxOption.editable = false;
comboBoxOption.currentText = "CCC"; // This doesn't show up.
QApplication::style()->drawComplexControl(QStyle::CC_ComboBox, &comboBoxOption, painter);
}
メソッド内で使用されていないためqwindowsxpstyle.cpp
、「実際の」コンボボックスのテキストがどこに描画されているかわかりません。Windows XP スタイルで使用されているように見える唯一の場所は(Line 2107、Qt 4.7.2) ですが、これら 2 つのクラスがどのように連携するかはわかりません。currentText
drawComplexControl
qcommonstyle.cpp