Results 1 to 4 of 4

Thread: QTableWidget alternating background color

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2010
    Location
    Somewhere in Southern Germany
    Posts
    8
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QTableWidget alternating background color

    I stripped my problem down to a simple testcase. I want to display the rows of a QTableWidget with alternating colors using a stylesheet.
    When running the program with the -stylesheet widgettest.qss option, I only see the default colors for the alternating background, not the colors defined in the stylesheet.
    I expected either the first or second entry to use yellow as background but that is not the case as you can see in the screenshot. Any Idea what I'm doing wrong?

    Here's the code
    mainwindow.h

    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QtGui/QMainWindow>
    5. #include <QTableWidget>
    6.  
    7. class MainWindow : public QMainWindow
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. MainWindow(QWidget *parent = 0);
    13. QTableWidget *myTable;
    14. ~MainWindow();
    15. };
    16.  
    17. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    mainwindow.cpp

    Qt Code:
    1. #include "mainwindow.h"
    2.  
    3. MainWindow::MainWindow(QWidget *parent)
    4. : QMainWindow(parent)
    5. {
    6. myTable=new QTableWidget();
    7. myTable->setColumnCount(1);
    8. myTable->setRowCount(5);
    9. myTable->show();
    10. QTableWidgetItem *myTableWidget=new QTableWidgetItem("First Entry ...");
    11. myTable->insertRow(0);
    12. myTable->setItem(0,0,myTableWidget);
    13. QTableWidgetItem *myTableWidget2=new QTableWidgetItem("Second Entry...");
    14. myTable->setItem(1,0,myTableWidget2);
    15. myTable->resizeColumnsToContents();
    16. myTable->setAlternatingRowColors(true);
    17. }
    18.  
    19. MainWindow::~MainWindow()
    20. {
    21.  
    22. }
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "mainwindow.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. MainWindow w;
    8. w.show();
    9.  
    10. return a.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 

    Stylesheet widgettest.qss
    Qt Code:
    1. alternate-background-color: yellow;
    2. background-color: red;
    3. }
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images
    Last edited by Aslan; 6th June 2011 at 12:32. Reason: typo

Similar Threads

  1. Replies: 2
    Last Post: 17th July 2010, 22:07
  2. Replies: 4
    Last Post: 17th July 2010, 05:47
  3. Replies: 1
    Last Post: 11th September 2009, 18:03
  4. Replies: 1
    Last Post: 23rd March 2009, 22:36
  5. QTableWidget Background Color
    By mbrusati in forum Qt Programming
    Replies: 2
    Last Post: 23rd September 2008, 19:38

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.