- changed status to resolved
QComboBox to show Qt::PenStyle.
Issue #171
resolved
Source: QComboBox to show Qt::PenStyle.
Better show pictures that show pen styles instead names of pen styles like we do now. Pen styles hard translate and this help hide internal names from user. And also this is normal behavior for graphical application. For this moment i could find example that show how to do this.
//![1] Begins
drawConfigBar = new QToolBar(QToolBar::tr("Draw Configuration Bar"),this);
drawConfigBar->setOrientation(Qt::Vertical);
drawConfigBar->setMovable(true);
drawConfigBar->setFloatable(true);
//![2]
QAction* newAction = NULL;
QComboBox* newComboBox = NULL;
//Pen Style
newComboBox = new QComboBox(drawConfigBar);
newComboBox->setToolTip(newComboBox->tr("Line style"));
newComboBox->setEditable(false);
newComboBox->setIconSize(QSize(80,14));
newComboBox->setMinimumWidth(80);
connect(newComboBox,SIGNAL(currentIndexChanged(int )),this,SLOT(slotLineStyleSelected(int)));
for (aaa = Qt::SolidLine; aaa < Qt::CustomDashLine; aaa++)
{
QPixmap pix(80,14);
pix.fill(Qt::white);
QBrush brush(Qt::black);
QPen pen(brush,2.5,(Qt::PenStyle)aaa);
QPainter painter(&pix);
painter.setPen(pen);
painter.drawLine(2,7,78,7);
newComboBox->addItem(QIcon(pix),"");
}
newComboBox->setCurrentIndex((int)Qt::SolidLine - 1);
drawConfigBar->addWidget(newComboBox);
//Pen width
newComboBox = new QComboBox(drawConfigBar);
newComboBox->setToolTip(newComboBox->tr("Line width"));
newComboBox->setEditable(false);
newComboBox->setIconSize(QSize(80,14));
newComboBox->setMinimumWidth(80);
connect(newComboBox,SIGNAL(currentIndexChanged(int )),this,SLOT(slotLineThicknessSelected(int)));
for (aaa = 1; aaa < 6; aaa++)
{
QPixmap pix(80,14);
pix.fill(Qt::white);
QBrush brush(Qt::black);
QPen pen(brush,(double)aaa,Qt::SolidLine);
QPainter painter(&pix);
painter.setPen(pen);
painter.drawLine(2,7,78,7);
newComboBox->addItem(QIcon(pix),"");
}
newComboBox->setCurrentIndex(0);
drawConfigBar->addWidget(newComboBox);
We have strings that represent in xml pen styles. Need to get this strings, generate pixmaps for pen styles, set for each pixmap string and after selection pen style to get string back. See QComboBox::itemData.
Comments (1)
-
Account Deleted - Log in to comment
Fixed issue
#171. QComboBox to show Qt::PenStyle.→ <<cset 9cb729519461>>