PDA

View Full Version : QStackedwidget stylesheet problem



mekalapandiyan@gmail.com
14th May 2013, 10:56
I have QStackedwidget in my application, In the first page, i have tablewidget.
i want to set stylesheet for Qtablewidget headerview.
but i can't able to set stylesheet.

I have tried following ways,

this->setStyleSheet(
" QHeaderView::section {"
" background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,"
" stop:0 #616161, stop: 0.5 #505050,"
" stop: 0.6 #434343, stop:1 #656565);"
" color: white;"
" padding-left: 4px;"
" border: 1px solid #6c6c6c;"
"}");

this->setStyleSheet( QStackedWidget QWidget#page { "
" QHeaderView::section {"
" background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,"
" stop:0 #616161, stop: 0.5 #505050,"
" stop: 0.6 #434343, stop:1 #656565);"
" color: white;"
" padding-left: 4px;"
" border: 1px solid #6c6c6c;"
"}"
"}");

but it is not working.

Santosh Reddy
14th May 2013, 11:34
A solution is already posted in your earlier thread LINK (http://www.qtcentre.org/threads/54558-How-to-set-style-sheet-for-stackwidget?p=244270&highlight=#post244270)

Let me put it again



this->setStyleSheet( QStackedWidget QWidget#page { " //<<<<<<<< Remove '{'
" QHeaderView::section {"
" background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,"
" stop:0 #616161, stop: 0.5 #505050,"
" stop: 0.6 #434343, stop:1 #656565);"
" color: white;"
" padding-left: 4px;"
" border: 1px solid #6c6c6c;"
"}" //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Remove '}'
"}");

mekalapandiyan@gmail.com
15th May 2013, 07:16
sorry, this solution is not working. i have tried already :(

Santosh Reddy
15th May 2013, 08:55
Then there is some else we should be knowing.

How are you creating the Ui
1. If you are using the designer, then make sure the QWidget's name is correct and the stylesheet is applied to a containing widget.
2. If you are creatig the using code, even then make sure the QWidget's name is correct.

The folloing code works on my windows



#include <QtGui>
#include <QApplication>

QWidget * createPage(const QString & name)
{
QTableWidget * tableWidget = new QTableWidget;
tableWidget->setObjectName(name);
tableWidget->setRowCount(10);
tableWidget->setColumnCount(10);
return tableWidget;
}

int main(int argc, char *argv[])
{
QApplication app(argc, argv);

QStackedWidget stackedWidget;
stackedWidget.showMaximized();

stackedWidget.addWidget(createPage("Page1"));
stackedWidget.addWidget(createPage("Page2"));

stackedWidget.setStyleSheet(
"QStackedWidget QTableWidget#Page1 QHeaderView::section {"
" background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,"
" stop:0 #616161, stop: 0.5 #505050,"
" stop: 0.6 #434343, stop:1 #656565);"
" color: white;"
" padding-left: 4px;"
" border: 1px solid #6c6c6c;"
"}"
"QStackedWidget QTableWidget#Page2 QHeaderView::section {"
" background-color: qlineargradient(x1:0, y1:0, x2:1, y2:1,"
" stop:0 #red, stop: 0.5 #green,"
" stop: 0.6 #green, stop:1 #pink);"
" color: white;"
" padding-left: 4px;"
" border: 1px solid #bule;"
"}");

stackedWidget.setCurrentIndex(0);
// stackedWidget.setCurrentIndex(1);

return app.exec();
}


If still it does not work, you better post a small compilable code with the problem

zgulser
15th May 2013, 13:47
What are you trying to do?

By the way, are we sure QStackedWidget has a headerview?

You may also give it a try from the qt designer.

Santosh Reddy
15th May 2013, 15:15
What are you trying to do?

By the way, are we sure QStackedWidget has a headerview?
OP is trying to apply the style for headerview of the QTableWidget which is in a QStackedWidget. As I understand style should only apply to QTableWidgets in the QStackedWidget, and not the other QTableWidgets outside QStackedWidget.