Results 1 to 1 of 1

Thread: problem with replacing a background image using signal / slot

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2010
    Posts
    1
    Qt products
    Qt4

    Default problem with replacing a background image using signal / slot

    Hi

    i want to make a simple chess program. So far i've made the board using QTableWidget and loaded the piece pictures in the cells of table. Now i wnat to use signal and slot so that when user clicks a cell and then click another cell the piece picture from first cell goes to second cell, But I don't know how to do it.

    Note that i don't want these "piece moves" obey the real chess rules. I only wnat to do the picture replacement between two cells . Later i will make them obey the rules.

    here is the code. in this code only table's item(0,0) has a picture. can anyone say how to write a code so that when i click that item then click to item(1,1) , picture "1.bmp" goes to background of item(1,1)?

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "mainwindow.h"
    3. #include <QHBoxLayout>
    4. #include <QTableWidget>
    5. #include <QHeaderView>
    6.  
    7. class Table : public QWidget
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. Table(QWidget *parent = 0);
    13. slots:
    14. //??????
    15.  
    16. };
    17.  
    18.  
    19. Table::Table(QWidget *parent)
    20. : QWidget(parent)
    21. {
    22. QHBoxLayout *hbox = new QHBoxLayout(this);
    23.  
    24. QTableWidget *table = new QTableWidget(8 , 8 , this);
    25.  
    26. table->setFixedSize(900,900);
    27. table->horizontalHeader()->setDefaultSectionSize(100);
    28. table->verticalHeader()->setDefaultSectionSize(100);
    29.  
    30. table->horizontalHeader()->setResizeMode(QHeaderView::Fixed);
    31. table->verticalHeader()->setResizeMode(QHeaderView::Fixed);
    32.  
    33. QString fileName = "/1.bmp";
    34. QPixmap pic(fileName);
    35.  
    36. QBrush brush(pic);
    37.  
    38. item->setBackground(brush);
    39.  
    40. table->setItem(0,0,item);
    41.  
    42. hbox->addWidget(table);
    43. setLayout(hbox);
    44. }
    45.  
    46. int main(int argc, char *argv[])
    47. {
    48. QApplication app(argc, argv);
    49.  
    50. Table table;
    51.  
    52. table.show();
    53.  
    54.  
    55. return app.exec();
    56. }
    To copy to clipboard, switch view to plain text mode 

    thanks
    Last edited by omid; 9th July 2010 at 14:19.

Similar Threads

  1. Signal and Slot Problem
    By waynew in forum Qt Programming
    Replies: 3
    Last Post: 5th June 2010, 10:49
  2. Easy Signal-Slot-Problem
    By nearlyNERD in forum Qt Programming
    Replies: 2
    Last Post: 6th March 2010, 22:33
  3. signal / slot problem
    By franco.amato in forum Newbie
    Replies: 13
    Last Post: 8th December 2009, 18:10
  4. problem with signal/slot mechanismus
    By MarkoSan in forum Qt Programming
    Replies: 10
    Last Post: 7th March 2008, 19:05
  5. problem with signal/slot
    By ihoss in forum Newbie
    Replies: 2
    Last Post: 24th August 2007, 22:59

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.