Results 1 to 4 of 4

Thread: How to get text with outlines

  1. #1
    Join Date
    Jun 2020
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default 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.

    Qt Code:
    1. void Ergebnisse::setupLayout()
    2. {
    3. m_ergebnisLayout = new QVBoxLayout();
    4.  
    5. QTabWidget* tabWidget = new QTabWidget();
    6. m_ergebnisLayout->addWidget(tabWidget);
    7.  
    8. m_ErgebnisTabelle = new QTableWidget(1, 3, this);
    9. QStringList header = {"ID","Ergebnis A","Ergebnis B"};
    10. m_ErgebnisTabelle->setHorizontalHeaderLabels(header);
    11. m_ErgebnisTabelle->verticalHeader()->hide();
    12.  
    13. QVBoxLayout* tab_vLayout = new QVBoxLayout();
    14. tab_vLayout->addWidget(m_ErgebnisTabelle);
    15.  
    16. QWidget* tableTab = new QWidget();
    17. tableTab->setLayout(tab_vLayout);
    18. tabWidget->addTab(tableTab, "Tabelle");
    19.  
    20. .... more tabs ....
    21. }
    22.  
    23.  
    24.  
    25. void Ergebnisse::plotErgebnisTabelle(QStringList header)
    26. {
    27. m_ErgebnisTabelle->clear();
    28. int numberItems = m_alleErgebnisse.size();
    29.  
    30. int rowCount = 0;
    31. QMapIterator<int,QPair<double,double>> iter_erg(m_alleErgebnisse);
    32. while (iter_erg.hasNext()){
    33. iter_erg.next();
    34. for(int i = 0; i < header.size(); i++){
    35. QString aktuellesItem;
    36. if(i == 0){
    37. aktuellesItem = QString::number(iter_erg.key());
    38. }
    39. else if(i == 1)
    40. {
    41. double aktuellerWert = iter_erg.value().first;
    42. aktuellesItem = (QString::number(aktuellerWert));
    43. }
    44. else
    45. {
    46. double aktuellerWert = iter_erg.value().second;
    47. aktuellesItem = (QString::number(aktuellerWert));
    48. }
    49.  
    50. QTableWidgetItem * protoitem = new QTableWidgetItem(aktuellesItem);
    51. protoitem->setTextAlignment(Qt::AlignCenter);
    52. m_ErgebnisTabelle->setItem(rowCount,i,protoitem);
    53. }
    54. rowCount++;
    55. }
    56. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to get text with outlines

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Jun 2020
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default 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 ?

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to get text with outlines

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. How to get text with outlines
    By bercker in forum Qt Programming
    Replies: 0
    Last Post: 12th June 2020, 10:50
  2. Replies: 4
    Last Post: 19th July 2016, 20:10
  3. Replies: 3
    Last Post: 19th January 2016, 18:22
  4. Replies: 1
    Last Post: 31st October 2014, 08:32
  5. Replies: 1
    Last Post: 3rd September 2008, 15:16

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.