How to get text with outlines
Hi guys,
i have a question:
I have a table
QTableWidget* m_ErgebnisTabelle;
This table will be shown in the GUI in a tabWidget.
In this itembased table , i will show some result values of some calculations.
QTableWidgetItem * protoitem = new QTableWidgetItem(aktuellesItem);
The text os white. But i want a text with a black outline.
I found a solution: https://www.qtcentre.org/threads/341...ent-background
In this solution a paintevent is used, but with a defined text. i have different values after every calculation.
And this post is 9 years old, maybe there is now another way to handle this - i dont know.
Here some code snippets, of how i setup and plot the table. The only thing missing, is the outlines.
Code:
void Ergebnisse::setupLayout()
{
m_ergebnisLayout->addWidget(tabWidget);
m_ErgebnisTabelle->setHorizontalHeaderLabels(header);
m_ErgebnisTabelle->verticalHeader()->hide();
tab_vLayout->addWidget(m_ErgebnisTabelle);
tableTab->setLayout(tab_vLayout);
tabWidget->addTab(tableTab, "Tabelle");
.... more tabs ....
}
void Ergebnisse
::plotErgebnisTabelle(QStringList header
) {
m_ErgebnisTabelle->clear();
int numberItems = m_alleErgebnisse.size();
int rowCount = 0;
QMapIterator<int,QPair<double,double>> iter_erg(m_alleErgebnisse);
while (iter_erg.hasNext()){
iter_erg.next();
for(int i = 0; i < header.size(); i++){
if(i == 0){
aktuellesItem
= QString::number(iter_erg.
key());
}
else if(i == 1)
{
double aktuellerWert = iter_erg.value().first;
aktuellesItem
= (QString::number(aktuellerWert
));
}
else
{
double aktuellerWert = iter_erg.value().second;
aktuellesItem
= (QString::number(aktuellerWert
));
}
protoitem->setTextAlignment(Qt::AlignCenter);
m_ErgebnisTabelle->setItem(rowCount,i,protoitem);
}
rowCount++;
}
}
Re: How to get text with outlines
Quote:
The text os white. But i want a text with a black outline.
Are you talking about the grid lines in the table? Look at QTableView::gridStyle() and QTableView::showGrid(). If you want to draw specific cells in your table with an outline around the text (to highlight them or give special emphasis), you will probably have to create a custom QAbstractItemDelegate to draw the text they way you want. I am not sure you can do that easily with a QTableWidget, but you can with a QTableView and QAbstractTableModel.
Re: How to get text with outlines
Thanks for your answer.
I want to outline the text, not the grid lines.
So instead of a QTableWidgetItem, i have to try it with a AbstractItemDelegate ?
Re: How to get text with outlines
Quote:
So instead of a QTableWidgetItem, i have to try it with a AbstractItemDelegate ?
QTableWidget / QTableWidgetItem are there for convenience, when you just want to display text or something else that is simple, so you don't have to go to the work of using a QTableView and QAbstractTableModel. If you want something fancier than what QTableWidgetItem can do, you probably need a delegate. Look at the Stars Delegate example for how to implement customized painting for a cell that persists after the user has stopped editing the cell.
If your table is display- (read-) only (or the cells you want to highlight are display only), then you may be able to use a cell widget (QTableWidget::setCellWidget()) containing a QLabel. QLabel inherits from QFrame, which allow you to place a border around it.