How to get the cursor position in a cell of QTableWidget - qt

I have a QTableWidget and I need to know the position of the cursor in a cell.
For QLineEdit there exists a function QLineEdit::cursorPosition( ).
Is there something similar for a cell in a QTableWidget or for a QTableWidgetItem?
Or any other method how I can find out the cursor position of the currentItem?
I hope it gets clearer with this picture. I have entered the cell item of row 27 and started to edit the cell item. The blinking cursor is between the second and the third Hallo. I want to find out at which position this blinking cursor is in the cell (same as for QLineEdit::cursorPosition)

Check this method:
QTableView::rowAt() - https://doc.qt.io/qt-5/qtableview.html#rowAt

Related

Getting rid of blank area at the bottom of a QListWidget

I'm using QListWidget with setItemWidget and when adding items to the list and scrolling down to the bottom I get this result:
So there's an area which is completely blank at the bottom (not selectable, in the image above the last item in the list has been selected)
How can I get rid of this blank area at the bottom of the list?
Please note that the height of the rows can be different within a list
Grateful for help and with kind regards,
Tord
It's possible to change the type of vertical scrolling that is done for list by using setVerticalScrollMode for the QListWidget so that the scrolling is done per pixel (instead of per item which is the default):
self.list_widget.setVerticalScrollMode(QtWidgets.QAbstractItemView.ScrollPerPixel)
The result is that rows that are in the top-most part of the QListWidget box can be drawn only in part, which in turn means that the blank area that exists when scrolling per item will disappear:
Reference documentation:
https://doc.qt.io/qt-5/qabstractitemview.html#verticalScrollMode-prop
I'm using exactly the same approach and I get rid of the blank area by creating a widget that contains my QListWidget and use :
listwidget.setFixedSize(widget.width(), listwidget.sizeHintForRow(0) * listwidget.count() + 2 * listwidget.frameWidth())
listwidget is you QListWidget object
widget is the widget that contains your QListWidget object

Always have an empty TableRow at the bottom of the TableView

I have a TableView where I add a new row by right clicking on the row below where I want to place the row and choosing "add" in a context menu. This becomes a problem when the TableView has so many rows that the entire view is filled with filled rows, since no empty rows are displayed. When this happens, I can only add a row above the row at the bottom, but not below it.
Adding a "dummy item" to the bottom of the TableView when that is used is not an option. I need to add a TableRow that has a item that is null, like the rows that usually fill out the viewport of the TableView when there's not enough items to fill the viewport.
Is there a way to make sure that there's always a TableRow with no item at the bottom of the table?
Edit: Adding a context menu to the entire TableView and automatically add row at the bottom when that is used is not an option either. This is because I need to add a style class to the row below the input index to provide the user with feedback on where the row will be placed. Therefore there needs to be a TableRow object to add the style class to.
Edit: I realize my text was a little bit messy. Here's an attempt at clarifying the actual behaviour I want:
I don't want the viewport to always display an empty row at the bottom, which would be some kind of "sticky row" behaviour. I want the actual table to display an empty row after the last row. I.e: When I'm in the "middle" of the list, and can't see the last row, no empty row should be displayed. The only time the empty row is needed is when I want to add an item at the end of the table list. Therefore when I scroll down so I see the end of the list, that's when I need an empty row. The reason I need this exact behaviour is explained in the original text.

Selected Item losing Highlight in QTableView

I have a problem with the extendedSelection of my QTableView.
The Problem is that i have some whitespace around my columns and rows and when i click this whitespace the highlighting of my selected Fields is lost.
Its not ocurring when i click somewhere else in my application, only in the whitespace.
Also when i set the selection mode to SingleSelection it works just fine.
here is a short gif to illustrate the problem
https://gyazo.com/8e4ae161aaff25a4afa1b588579ddd01
thank you everyone who can help me
sincerely
Because that white region belongs to QTableWidget, so when you click that place it resets the selection and selected cell is gone since none of cell is selected. But when you click outside of the QTableWidget, selection state still exists.So If you do not want to this, you can increase column widths like this:
ui.tableWidget->setColumnWidth(columnNumber,columnWidht);
or you can decrease the width of QTableWidget to fit the columns. So user can not see and click this white region.

Why not editable cell has a cursor?

I have a grid, I have set:
this.gridColAlias1.AppearanceHeader.Options.UseTextOptions = true;
this.gridColAlias1.AppearanceHeader.TextOptions.HAlignment =DevExpress.Utils.HorzAlignment.Near;
this.gridColAlias1.OptionsColumn.AllowEdit = false;
I see the column on my grid is not editable, but anyway I see a cursor on the cell of that column and hence it pretends editable. Why this happens and how could I get rid of the cursor?
Thanks!
What do you mean when you talk about the cursor? There is no cursor (caret) within the cell when the OptionsColumn.AllowEdit property is set to false. Maybe you mean a focus rectangle?To avoid the focus rectangle to be drawn on the particular column cell, you can make this column unfocusable via the OptionsColumn.AllowFocus property.

How to select Row in QTableView?

I am new to QT, and I'm using QTableView, as shown below:
On the left side of the table, Qt is automatically showing a row number, as I've noted in red. How do I get rid of these numbers?
My other problem is, if I click any cell, only that cell is selected. How can I make it to where, when a user clicks a cell, the entire row is selected, like I noted in pink? For example, if I click the testApp-copy.itr cell then the entire third row should be selected.
Use
table->verticalHeader()->hide();
to get the vertical header and hide it, and
table->setSelectionBehavior(QAbstractItemView::SelectRows);
to make QTableView only select whole rows.
You may also want to specify the selection mode.

Resources