Results 1 to 5 of 5

Thread: Cutom signal on mouse click at top left corner of QTableWidget

  1. #1
    Join Date
    May 2009
    Posts
    55
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Cutom signal on mouse click at top left corner of QTableWidget

    Hi,

    I need to add some functionality (change header items texts) after user click on top left corner of qtablewidget. I try to use signal itemSelectionChanged() but it works only first time because selection is not changed until user click on some other table cell. Simply I need after every click to top left corner cell switch header text from decimal to hexadecimal or whatever. How can I use some mouse event or signal to have such a functionality? Thanks in advance

  2. #2
    Join Date
    May 2010
    Posts
    24
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Cutom signal on mouse click at top left corner of QTableWidget

    If by top left corner, you mean the first column header, you can get the horizontal header from QTableView::horizontalHeader, connect its sectionClicked(int) signal to your custom slot and test the column index given by the signal parameter.

  3. #3
    Join Date
    May 2009
    Posts
    55
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Cutom signal on mouse click at top left corner of QTableWidget

    Hi,

    thanks for hint but signal is emmited after click on header item 0 and so on. But I need signal emited when click let's say -1 column( top left).

    My code:
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent)
    2. : QMainWindow(parent), ui(new Ui::MainWindow)
    3. {
    4. ui->setupUi(this);
    5. connect(ui->tableWidget->horizontalHeader(), SIGNAL(sectionClicked(int)), this, SLOT(my_slot(int)));
    6. }
    7.  
    8. MainWindow::~MainWindow()
    9. {
    10. delete ui;
    11. }
    12.  
    13.  
    14. void MainWindow::my_slot(int index)
    15. {
    16. qDebug() << index;
    17. }
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images

  4. #4
    Join Date
    May 2010
    Posts
    24
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Cutom signal on mouse click at top left corner of QTableWidget

    You meant the "corner button".

    You can either try to redefine the selectAll() method by deriving QTableWidget, because this is the virtual slot that is called when you click on it. You should probably test that the sender() is a QAbstractButton and has the QTableWidget as parent.

    Or get the button, disconnect any slot, and reconnect your own:
    Qt Code:
    1. QAbstractButton *cornerButton = tableWidget->findChild<QAbstractButton*>();
    2. // Since it's not part of the API, there is no guarantee it exists
    3. if (cornerButton)
    4. {
    5. cornerButton->disconnect();
    6. connect(cornerButton, SIGNAL(clicked()), ..., ...);
    7. }
    To copy to clipboard, switch view to plain text mode 

  5. The following 2 users say thank you to alexisdm for this useful post:

    Ashkan_s (19th September 2012), binaural (30th May 2010)

  6. #5
    Join Date
    May 2009
    Posts
    55
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Cutom signal on mouse click at top left corner of QTableWidget

    Thanks for advice. I choose solution 1. I post it here so somebody else could use it .
    mainwindow.h
    Qt Code:
    1. class my_table : public QTableWidget
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. my_table(int row, int col, QWidget *parent = 0);
    7. ~my_table();
    8.  
    9. private:
    10.  
    11.  
    12. private slots:
    13. void selectAll ();
    14. };
    To copy to clipboard, switch view to plain text mode 

    mainwindow.cpp
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent)
    2. : QMainWindow(parent), ui(new Ui::MainWindow)
    3. {
    4. ui->setupUi(this);
    5.  
    6. my_table *table = new my_table(2,2,this);
    7. table->setGeometry(10,20,250,190);
    8.  
    9.  
    10. }
    11.  
    12. MainWindow::~MainWindow()
    13. {
    14. delete ui;
    15. }
    16.  
    17. my_table::my_table(int row, int col, QWidget *parent)
    18. : QTableWidget(row, col, parent)
    19. {
    20.  
    21. }
    22.  
    23. my_table::~my_table()
    24. {
    25.  
    26. }
    27.  
    28. void my_table::selectAll(void)
    29. {
    30. qDebug() << "select";
    31. }
    To copy to clipboard, switch view to plain text mode 

    Thanks

Similar Threads

  1. Replies: 10
    Last Post: 29th May 2010, 18:42
  2. QTableWidget - Using top left corner cell
    By SteveH in forum Newbie
    Replies: 6
    Last Post: 12th March 2010, 19:33
  3. QDateEdit and mouse click signal
    By ouekah in forum Newbie
    Replies: 2
    Last Post: 23rd February 2010, 19:00
  4. Emulating Enter key with left mouse click
    By wconstan in forum Newbie
    Replies: 6
    Last Post: 30th December 2009, 16:16
  5. Replies: 1
    Last Post: 7th September 2008, 10:47

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.