【问题标题】:QTableView - Selection background colorQTableView - 选择背景颜色
【发布时间】:2010-10-14 11:32:54
【问题描述】:

我正在使用以下代码在模拟器(S60)(诺基亚 Qt SDK)中设置表格的样式。

searchTable->setStyleSheet("background: rgb(255,255,255);color:rgb(0,0,0); font-family:Arial Narrow;font-size:20px; border: 4px outset rgb(255,255,255);gridline-color: #669933;"
                           "selection-background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #486909, stop: 1 white);"
                              );

但是当我选择数据中的元素时,我得到了以下输出。请找到附件。

请帮助我....我做错了什么..提前谢谢。

【问题讨论】:

    标签: qt qt4 qtableview


    【解决方案1】:

    我猜你的错误是你只为 QTableView 而不是为它的所有子小部件设置样式表:单元格。您可以尝试将样式代码写入“.qss”文件,将其添加到应用的资源文件中,然后使用以下代码将其加载到 main.cpp:

    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        MainWindow w;
        QFile file(":/qss/stylesheet.qss");
        file.open(QFile::ReadOnly);
        QString styleSheet = QLatin1String(file.readAll());
        file.close();
        qApp->setStyleSheet(styleSheet);
    
        w.show();
    }
    

    在您的样式文件中,您必须编写如下内容:

    QLineEdit{
    border: 2px solid grey;
    border-radius: 10px;
    padding: 0 8px;
    background: white;
    selection-background-color:darkgrey;
    }
    

    通过这种方式,所有 QLineEdit 小部件都将与您的样式规则一起显示。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-13
      • 2018-03-04
      • 2018-10-28
      • 1970-01-01
      • 1970-01-01
      • 2021-12-19
      相关资源
      最近更新 更多