Results 1 to 12 of 12

Thread: Image on button

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Image on button

    Quote Originally Posted by windkracht8
    In Qt4 it's not posible anymore to put an image on an button.
    It is possible as it works for me (on both Linux and windows) --- you just have to use correct paths.

  2. #2
    Join Date
    Aug 2006
    Posts
    27
    Thanks
    2
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Image on button

    Quote Originally Posted by jacek
    It is possible as it works for me (on both Linux and windows) --- you just have to use correct paths.
    Could you please post your code on howto do this here please.

    To clear up things:
    This is in init: (Could have been done with QDir:rogPath(), but not implemented yet)
    Qt Code:
    1. #ifdef _WIN32
    2. progPath = "D:/qt/progs/sudoku/"; //windows
    3. #else
    4. progPath = "/home/bartv/progs/sudoku/"; //linux
    5. #endif
    6.  
    7. pWit.load("knopWit.png");
    8.  
    9. palWit.setColor(QPalette::Base,QColor(255,255,255));
    10. palWit.setColor(QPalette::Button,QColor(255,255,255,0));
    11. palWit.setColor(QPalette::Text,QColor(0,0,0,255));
    12. palWit.setColor(QPalette::ButtonText,QColor(0,0,0,255));
    13.  
    14. label->setPixmap(pWit);
    15. but->setPalette(palWit);
    16. e->setPalette(palWit);
    To copy to clipboard, switch view to plain text mode 

    @Brandybuck:
    With Qt3.3, not with Qt4 anymore, sorry for the mixup.

    Cheers,
    Bart.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Image on button

    Quote Originally Posted by windkracht8
    Could you please post your code on howto do this here please.
    Try something like:
    Qt Code:
    1. pWit.load( QCoreApplication::applicationDirPath() + QDir::separator() + "knopWit.png" );
    2. but->setIcon( pWit );
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Aug 2006
    Posts
    27
    Thanks
    2
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Image on button

    That give's me a small icon on the button. I need the entire image to be the entire button.
    So people see my image not the button.

    Can't put an image on the net at the moment, no ftp allowd here.

    But I got it to work. It's only a shame I need to put an label behind the button.

    Cheers,
    Bart.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Image on button

    Quote Originally Posted by windkracht8
    That give's me a small icon on the button. I need the entire image to be the entire button. So people see my image not the button.
    Maybe QPushButton::setFlat() will be enough?

    Quote Originally Posted by windkracht8
    Can't put an image on the net at the moment, no ftp allowd here.
    Just post it as attachment (click "Manage Attachments" below the editor).

  6. #6
    Join Date
    Aug 2006
    Posts
    27
    Thanks
    2
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Image on button

    All ready got that set.

    knop.cpp is an custom widget which is placed a couple of times in an frame on the main form.
    Complete code included. Maybe someone is interrested in a qt cross-platform sudoku game. It generates games on different levels.

    Now I just need to get it up and running on my phone. (windows mobile)

    knop.cpp:
    Qt Code:
    1. #include "knop.h"
    2. #include "bc.h"
    3.  
    4. #include <QVariant>
    5. #include <QLineEdit>
    6. #include <QPushButton>
    7. #include <QString>
    8. #include <QApplication>
    9. #include <QMessageBox>
    10. #include <QTimer>
    11.  
    12. knop::knop(QWidget* parent)
    13. : QWidget(parent)
    14. {
    15. setMaximumSize( QSize( 50, 50 ) );
    16.  
    17. label = new QLabel("label", this);
    18. label->setGeometry( QRect( 0, 0, 50, 50 ) );
    19. label->setText("");
    20.  
    21. but = new QPushButton("but", this);
    22. but->setGeometry( QRect( 0, 0, 50, 50 ) );
    23. but->setCheckable(true);
    24. but->setFont(QFont("Bitstream Vera Sans",22,QFont::Bold));
    25. but->setFlat(true);
    26.  
    27. e = new QLineEdit("e", this);
    28. e->setGeometry( QRect( 5, 5, 40, 10 ) );
    29. QFont e_font( e->font() );
    30. e_font.setPointSize( 10 );
    31. e->setFont( e_font );
    32. e->setFrame( FALSE );
    33.  
    34. resize( QSize(50, 50).expandedTo(minimumSizeHint()) );
    35. connect( but, SIGNAL(clicked()), SLOT(butClick()) );
    36. init();
    37.  
    38. }
    39.  
    40. knop::~knop(){}
    41.  
    42. void knop::init()
    43. {
    44. progPath = QCoreApplication::applicationDirPath() + "/";
    45.  
    46. pWit.load(progPath + "include/knopWit.png");
    47. pRood.load(progPath + "include/knopRood.png");
    48. pGroen.load(progPath + "include/knopGroen.png");
    49.  
    50. palWit.setColor(QPalette::Base,QColor(255,255,255));
    51. palWit.setColor(QPalette::Button,QColor(255,255,255,0));
    52. palWit.setColor(QPalette::Text,QColor(0,0,0,255));
    53. palWit.setColor(QPalette::ButtonText,QColor(0,0,0,255));
    54.  
    55. palRood.setColor(QPalette::Base,QColor(255,0,0));
    56. palRood.setColor(QPalette::Text,QColor(0,0,0,255));
    57. palRood.setColor(QPalette::ButtonText,QColor(0,0,0,255));
    58.  
    59. palGroen.setColor(QPalette::Base,QColor(0,255,0));
    60. palGroen.setColor(QPalette::Text,QColor(0,0,0,255));
    61. palGroen.setColor(QPalette::ButtonText,QColor(0,0,0,255));
    62.  
    63. palClick.setColor(QPalette::Base,QColor(200,200,200));
    64. palClick.setColor(QPalette::Button,QColor(200,200,200,255));
    65. palClick.setColor(QPalette::Text,QColor(0,0,0,255));
    66. palClick.setColor(QPalette::ButtonText,QColor(0,0,0,255));
    67.  
    68. label->setPixmap(pWit);
    69. but->setPalette(palWit);
    70. e->setPalette(palWit);
    71.  
    72. }
    73. void knop::setNum(QString num)
    74. {
    75. but->setText(num);
    76. current = num;
    77. e->setText("");
    78. }
    79.  
    80. void knop::butClick()
    81. {
    82. bC* bC1 = new bC(knopRij,knopCol);
    83. QApplication::postEvent(this->parent()->parent(), bC1);
    84. }
    85. void knop::unClick()
    86. {
    87. but->setChecked(false);
    88. but->setPalette(palWit);
    89. e->setPalette(palWit);
    90. }
    91. void knop::hint(QString hoort)
    92. {
    93. QTimer::singleShot(2000, this, SLOT(terug()));
    94. but->setText(hoort);
    95. but->setPalette(palGroen);
    96. e->setPalette(palGroen);
    97. }
    98. void knop::terug()
    99. {
    100. but->setText(current);
    101. but->setPalette(palWit);
    102. e->setPalette(palWit);
    103. }
    104. void knop::setRood()
    105. {
    106. but->setPalette(palRood);
    107. e->setPalette(palRood);
    108. QTimer::singleShot(5000, this, SLOT(terug()));
    109. }
    110. void knop::setGroen()
    111. {
    112. but->setPalette(palGroen);
    113. e->setPalette(palGroen);
    114. QTimer::singleShot(5000, this, SLOT(terug()));
    115. }
    116. void knop::clearEdit()
    117. {
    118. e->setText("");
    119. }
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images
    Attached Files Attached Files

Similar Threads

  1. "sensitising" an image
    By TheKedge in forum Qt Programming
    Replies: 2
    Last Post: 28th June 2006, 07:21
  2. Fast image drawing/scaling in Qt 3.3
    By eriwik in forum Qt Programming
    Replies: 1
    Last Post: 21st June 2006, 10:45
  3. problem with the back ground image
    By Seema Rao in forum Qt Programming
    Replies: 1
    Last Post: 17th April 2006, 21:34
  4. How and when to repaint a widget ?
    By yellowmat in forum Newbie
    Replies: 7
    Last Post: 3rd April 2006, 16:36
  5. Question about updating an image on screen
    By SkripT in forum Qt Programming
    Replies: 1
    Last Post: 24th February 2006, 19:01

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
  •  
Qt is a trademark of The Qt Company.