Results 1 to 14 of 14

Thread: Popup menu in TabelView on one row

  1. #1
    Join Date
    Apr 2009
    Posts
    75
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Popup menu in TabelView on one row

    Hi everyone,

    I have a QTabelView with a few rows and I would like to make a Popup menu that when I selectm for example the first item in the menu, that shows me the value of the first cell in the current row.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Popup menu in TabelView on one row

    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Apr 2009
    Posts
    75
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Popup menu in TabelView on one row

    Quote Originally Posted by wysota View Post

    I'm sorry for my english - whose words don't you understand, I'll try to explain more.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Popup menu in TabelView on one row

    I understand the words. I don't understand why do you expect others to guess what you are having problems with. So far you told us what you were working on, not more. So I replied that I was very happy for you that you had something to fill your time with.

    On the other hand if you want to ask for something, spare 30 minutes and read through the text behind the link I gave you (pay special attention to the "Be precise and informative about your problem" and "Questions Not To Ask" parts) and then restate your problem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Apr 2009
    Posts
    75
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Popup menu in TabelView on one row

    Yes you are right.


    So, I've recasted my problem.

    How to make a Popup menu which is connected to TableView and when I press one item on menu displays the value of the first cell in selected row?

    So, I've two problems:
    1. How to create a Popup menu connected to TableView?
    2. How do display the value o some cell in selected row.



    Forgive me, I did't want to do anyone a clairvoyant.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Popup menu in TabelView on one row

    Quote Originally Posted by TomASS View Post
    1. How to create a Popup menu connected to TableView?
    There are basically three ways to do that. Take a look at QWidget::contextMenuPolicy property to see description of all of them.

    2. How do display the value o some cell in selected row.
    Use QModelIndex::data() to retrieve the value of an index of a table.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Apr 2009
    Posts
    75
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Popup menu in TabelView on one row

    Thanks,

    I've made:

    Qt Code:
    1. TableResult = new QTableWidget;
    2. TableResult->setRowCount(3);
    3. TableResult->setColumnCount(5);
    4. TableResult->setContextMenuPolicy(Qt::ActionsContextMenu);
    5.  
    6. newAct = new QAction(tr("&New"), this);
    7. newAct->setShortcuts(QKeySequence::New);
    8. newAct->setStatusTip(tr("Create a new file"));
    9. connect(newAct, SIGNAL(triggered()), this, SLOT(newFile()));
    10.  
    11. QMenu menu(TableResult);
    12. menu.addAction(newAct);
    To copy to clipboard, switch view to plain text mode 
    but, unfortunately, when I'm pressing a right mouse button any menu does not appear :/

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Popup menu in TabelView on one row

    It doesn't work that way. You have to add the action to the widget, not to some temporary menu object.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. The following user says thank you to wysota for this useful post:

    TomASS (27th September 2009)

  10. #9
    Join Date
    Apr 2009
    Posts
    75
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Popup menu in TabelView on one row

    Ok, now I've:

    Qt Code:
    1. newAct = new QAction(tr("&New"), this);
    2. newAct->setShortcuts(QKeySequence::New);
    3. newAct->setStatusTip(tr("Create a new file"));
    4. TableResult->addAction(newAct);
    5. TableResult->setContextMenuPolicy(Qt::ActionsContextMenu);
    6. connect(newAct, SIGNAL(triggered()),TableResult,SLOT(newFile()));
    To copy to clipboard, switch view to plain text mode 

    and
    Qt Code:
    1. void MainWindow::newFile(){
    2. QMessageBox::critical(0,"ttt1","ttt2");
    3. }
    To copy to clipboard, switch view to plain text mode 

    of course I've in header file:
    Qt Code:
    1. class MainWindow : public QMainWindow
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. MainWindow(QWidget *parent = 0);
    7. ~MainWindow();
    8. QAction *newAct;
    9. QTableWidget *TableResult;
    10.  
    11. private slots:
    12. void newFile();
    13.  
    14. private:
    15. int t;
    16. };
    To copy to clipboard, switch view to plain text mode 

    but, menu appears, but when I click on "new file" nothing happens :/ Method MainWindow::newFile will not start
    Last edited by TomASS; 27th September 2009 at 20:59.

  11. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Popup menu in TabelView on one row

    Qt Code:
    1. connect(newAct, SIGNAL(triggered()),TableResult,SLOT(newFile()));
    To copy to clipboard, switch view to plain text mode 
    You connect the signal to a slot in the table, not in the main window.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #11
    Join Date
    Apr 2009
    Posts
    75
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Popup menu in TabelView on one row

    Thank you for your quick response and for your patience, but how can I connect the signal to TableView?

    And second question, how can I read a value of selected (by showing menu) row, you've wrote by "QModelIndex::data()" but in newFile() funcition I haven't data :/

  13. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Popup menu in TabelView on one row

    Quote Originally Posted by TomASS View Post
    Thank you for your quick response and for your patience, but how can I connect the signal to TableView?
    Are you asking me about the prototype of QObject::connect() or something else?

    ... but in newFile() funcition I haven't data :/
    If you have the selected row, you have its index. When you have its index, you can call data() on it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  14. The following user says thank you to wysota for this useful post:

    TomASS (28th September 2009)

  15. #13
    Join Date
    Sep 2009
    Location
    Aachen, Germany
    Posts
    60
    Thanks
    2
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Popup menu in TabelView on one row

    Quote Originally Posted by TomASS View Post
    Thank you for your quick response and for your patience, but how can I connect the signal to TableView?
    You have declared the slot in your MainWindow Class, but connected the Signal to your TreeWidget. So, to connect to your newFile() Slot, your connect would have to look like this:
    Qt Code:
    1. connect(newAct, SIGNAL(triggered()), this, SLOT(newFile()));
    To copy to clipboard, switch view to plain text mode 
    Take a look at the link wysota posted if you want to know more about this.

    Quote Originally Posted by TomASS View Post
    And second question, how can I read a value of selected (by showing menu) row, you've wrote by "QModelIndex::data()" but in newFile() funcition I haven't data :/
    As you're using a TableWidget, not a TableView, simply call
    Qt Code:
    1. TableResult->currentItem()->data(...)
    To copy to clipboard, switch view to plain text mode 
    Or, if you need data from another column in the row
    Qt Code:
    1. TableResult->item(TableResult->currentRow(), your Column)->data(...)
    To copy to clipboard, switch view to plain text mode 
    If you want to use a TableView, you'll have to work with indexes, of course, but that's pretty much the same.

  16. The following user says thank you to ChiliPalmer for this useful post:

    TomASS (28th September 2009)

  17. #14
    Join Date
    Apr 2009
    Posts
    75
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Popup menu in TabelView on one row

    Thanks a lot!

    I's working!
    Last edited by TomASS; 28th September 2009 at 09:25.

Similar Threads

  1. Replies: 3
    Last Post: 17th May 2009, 20:17
  2. Disable popup menu
    By febil in forum Qt Programming
    Replies: 7
    Last Post: 26th March 2009, 12:21
  3. Popup menu for a QGraphicsItem?
    By Morea in forum Qt Programming
    Replies: 4
    Last Post: 4th February 2009, 21:27
  4. multi level menu popup
    By MrGarbage in forum Qt Programming
    Replies: 1
    Last Post: 28th September 2007, 08:06
  5. PopUp a Menu when showing FullScreen
    By Lele in forum Qt Programming
    Replies: 2
    Last Post: 29th May 2007, 10:04

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.