Qtableview Right-click menu to determine whether the position is reasonable

Source: Internet
Author: User

Minor bugs in the practice process:
When I right-clicked on the view margin, that is, I did not select the row with the content, the program was interrupted because I did not make positional judgments and directly get the row content assigned to other variables.

QModelIndex temp = m->index(right_click.row(),1);

Solution:
Determines whether the selected row is within the line range of our model.
How do I get the line of the model?

ui.table_view->model()->rowCount();

Actually, we don't need to use

right_click.row() < ui.table_view->model()->rowCount();

Since the display of the TableView in the array, starting from table 0 to rowCount-1, and the downward margin is indicated by-1.
So all we have to do is to determine if the currently clicked row equals-1, that is, the blank space is selected, and no data extraction is required.

if( right_click.row() != -1 ){    //dofor you}else{}

Qtableview Right-click menu to determine whether the position is reasonable

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.