Results 1 to 5 of 5

Thread: Changing style of Button,Label...

  1. #1
    Join Date
    Apr 2011
    Posts
    25
    Qt products
    Qt/Embedded
    Platforms
    Symbian S60

    Default Changing style of Button,Label...

    hello friends

    Actually i want to set the background image of an button using codding,not in the qtDesigner Property part..so hw can i do it..moreover hw can i change the font color,font style of an button,label,...

    with regards
    Anshuman

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Changing style of Button,Label...

    Use the palette to change things: QPalette. Or create your own style: QStyle.

  3. #3
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Changing style of Button,Label...

    Also, be prepared for bitter disappointment when your code fails to run on some platforms (Windows) while running perfectly elsewhere. For example, it is impossible to do something as simple as setting the background color of a button programatically when running under Windows.

    Unless you use stylesheets. But once you open that door, you're responsible for defining the entire style of the button - border, margin, corner rounding, shading, font color, background color....

  4. #4
    Join Date
    Apr 2011
    Posts
    25
    Qt products
    Qt/Embedded
    Platforms
    Symbian S60

    Default Re: Changing style of Button,Label...

    hello lykurg

    Actually i had use QStyle but its nt working..i will send u the code..u just check it

    Qt Code:
    1. QString style="QPushButton::forwardBut { width:26px; height:17px;"
    2. "image: url(icons:right_arrow.png); } ";
    3.  
    4. QPushButton *forwardBut=new QPushButton("->");
    5. forwardBut->setStyleSheet(style);
    To copy to clipboard, switch view to plain text mode 

    with regards
    Anshuman

  5. #5
    Join Date
    Apr 2011
    Posts
    25
    Qt products
    Qt/Embedded
    Platforms
    Symbian S60

    Default Re: Changing style of Button,Label...

    hello sir

    As per ur suggestion i will be able to create an array of buttons consisting of six rows and seven colums....which look like that.

    <- April -> // Arow sign are in button..representing forward and backward to change month

    M T W Th F S SU //weeks are in label

    1 2 3 4 5 6 7

    8 9 10 11 12 13 14

    .................................................. .......

    .......................42

    Number in bold are buttons stored in an array of a[6][7]...

    now i am trying to update each button on changing of month...as per calender work..please help me to suggest that hw can i implement this to work it as calender...as far of my code that i had wrritten is given below..from there hw can i proceed please suggest...
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :QMainWindow(parent),ui(new Ui::MainWindow)
    2. {
    3.  
    4. ui->setupUi(this);
    5.  
    6. QWidget *centralWidget = new QWidget;
    7. selectedDate=QDate::currentDate();
    8. x=selectedDate.month();
    9. // QString style="QPushButton::forwardBut { width:26px; height:17px;"
    10. // "image: url(icons:right_arrow.png); } ";
    11.  
    12. int count=1,i,j;
    13. MonthLbl=new QLabel("MonthDisplay");
    14. MonthLbl->setText(selectedDate.longMonthName(x));;
    15. QPushButton *button[10][10],*forwardBut,*backwardBut;
    16.  
    17. forwardBut=new QPushButton();
    18.  
    19. forwardBut->setIcon(QIcon("C:/Plackal/QtWorkspace/CustomCalender/Images/back-icon.PNG"));
    20.  
    21. backwardBut=new QPushButton("<-");
    22. QGridLayout *controlsLayout = new QGridLayout;
    23. QGridLayout *hWeek = new QGridLayout;
    24.  
    25. QLabel *blankLbl=new QLabel;
    26.  
    27. QLabel *blank=new QLabel;
    28.  
    29. QLabel *weekLbl[7];
    30. for(i=1;i<=7;i++)
    31. {
    32. weekLbl[i]=new QLabel(selectedDate.shortDayName(i));
    33. hWeek->addWidget(weekLbl[i],1,i);
    34. }
    35.  
    36.  
    37. for(i=0;i<7;i++)
    38. {
    39. for(j=0;j<7;j++)
    40. {
    41. if(count<=42)
    42. {
    43. button[i][j] = new QPushButton(QString::number(count));
    44. controlsLayout->addWidget(button[i][j], i, j);
    45. count++;
    46. }
    47. }
    48. }
    49.  
    50. controlsLayout->setMargin(0);
    51. controlsLayout->setHorizontalSpacing(0);
    52. controlsLayout->setVerticalSpacing(0);
    53. h->addWidget(backwardBut);
    54. h->addWidget(blank);
    55. h->addWidget(MonthLbl);
    56. h->addWidget(blank);
    57. h->addWidget(forwardBut);
    58. hLbl->addWidget(blankLbl);
    59. v->addLayout(h);
    60. v->addLayout(hLbl);
    61. v->addLayout(hWeek);
    62. v->addLayout(controlsLayout);
    63. v->addWidget(txtDate);
    64. //centralWidget->setLayout(controlsLayout);
    65. centralWidget->setLayout(v);
    66. setCentralWidget(centralWidget);
    67. connect(forwardBut,SIGNAL(clicked()),this,SLOT(monthForward()));
    68. connect(backwardBut,SIGNAL(clicked()),this,SLOT(monthBackward()));
    69. }
    70. void MainWindow::monthForward()
    71. {
    72. MonthLbl->setText(selectedDate.longMonthName(++x));
    73. if(x>12)
    74. x=1;
    75. }
    76. void MainWindow::monthBackward()
    77. {
    78. MonthLbl->setText(selectedDate.longMonthName(--x));
    79. if(x<2)
    80. x=13;
    81. }
    To copy to clipboard, switch view to plain text mode 
    with regards
    Anshuman

Similar Threads

  1. Changing text of button in no relation to button
    By Sabre Runner in forum Newbie
    Replies: 22
    Last Post: 23rd September 2010, 13:29
  2. Replies: 6
    Last Post: 21st August 2010, 22:09
  3. Replies: 1
    Last Post: 2nd August 2010, 06:40
  4. changing QPushButton label
    By Ferric in forum Newbie
    Replies: 3
    Last Post: 31st January 2010, 10:57
  5. label Text is not changing using Qt Linguist
    By thomasjoy in forum Qt Tools
    Replies: 59
    Last Post: 8th October 2007, 16:24

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.