Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTableView background-color lets text disappear

QTableView background-color lets text disappear

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 2.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    goocreations
    wrote on last edited by
    #1

    I subclassed QTableWidget as follows:

    @MyTableWidget::MyTableWidget(QWidget *parent)
    : QTableWidget(parent)
    {
    setStyleSheet("QTableView{ color: blue; background-color: transparent; }");
    }

    void MyTableWidget::paintEvent(QPaintEvent *event)
    {
    QTableWidget::paintEvent(event);
    QStyleOption option;
    option.init(this);
    QPainter painter(viewport());
    style()->drawPrimitive(QStyle::PE_Widget, &option, &painter, this);
    }@

    This works perfectly, my table cells' text is blue on a transparent background. However, the moment I change the table view's background-color to anything but transparent, the background-color shows, but the text of the table cells disappear.

    I'm not sure how QTableView is implmented, but since transparent works, I assume that somehow the background is moved forward (and placed over the text) once the stylesheet is set (only happens if stylesheet has background-color). So if transparent is set, you can basically view the text "through" the background.

    Any suggestions on how to overcome this problem?

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved