[Qt-interest] QPalette

Alvaro Sánchez varo26278 at gmail.com
Mon May 4 23:23:39 CEST 2009


Hi all,

   I'm trying to change the button color (no border) using the below code:

   QPalette palette = ui.pushButton->palette();
   palette.setColor( QPalette::Normal, QPalette::Button, QColor(Qt::red) );
   ui.pushButton->setPalette(palette);



   ui.pushButton->setAutoFillBackground(true);

   and the result is wrong, the pushButton border is red instead of the
button, does anybody know how to resolve it?

   If I use QStyleSheet to define a "background-color: red" to apply the
pushButton, the result is correct, but my memory grows up, does anybody know
why is happening?

#include "ui_testqt.h"

class testqt : public QDialog
 {
     Q_OBJECT

 public:
     testqt(QWidget *parent = 0);


     void Refresh();

 private slots:
     void on_pushButton_pressed();
     void closeEvent (QCloseEvent *);


 private:
     Ui_Dialog ui;

     bool bStatus;


 };


include "testqt.h"

testqt::testqt(QWidget *parent)
     : QDialog(parent)
 {
     QString qtstylesheet = "background-color: yellow";

     ui.setupUi(this);
     bStatus = false;
 }

void testqt::on_pushButton_pressed()
{
   bStatus = !bStatus;
}

void testqt::Refresh()
{
    QString qtstylesheet = "background-color: yellow";
    QString qtstylesheet2 = "background-color: red";

   if (bStatus)
   {
      ui.pushButton->setStyleSheet(qtstylesheet);
   }
   else
   {
      ui.pushButton->setStyleSheet(qtstylesheet2);
   }

More thans,

Álvaro

}

void testqt::closeEvent (QCloseEvent* )
{
   emit destroyed();
}



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

   testqt *mytestqt = new testqt();
   mytestqt->show();

   while (true)
   {
      mytestqt->Refresh();
      app->processEvents(QEventLoop::ExcludeSocketNotifiers,1000);
   }

}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090504/084fa451/attachment.html 


More information about the Qt-interest-old mailing list