QTableWidgetItem displays three dots instead of full text - c++

I'm using a QTableWidget with four column witch i programaticaly fill with QTableWidgetItem in a loop. it's working but the full text is not displaying, it show three dots instead like there isn't enough space:
if i double click on a row it will display the whole text:
How to set QTableWidgetItem programatically to fill all available space, or disable the 3 dots system and just display the whole text event if it will overflow ?
Here my simplified code that just fill the second problematic column:
vector<OperationLine> lines = db->getOperationLines(ui->dateEditFrom->date(),ui->dateEditTo->date());
ui->operationTableWidget->setRowCount(lines.size());
ui->operationTableWidget->setTextElideMode(Qt::ElideNone);
for(int i=0;i<lines.size();i++){
QTableWidgetItem* libelle_item = new QTableWidgetItem(lines.at(i).libelle);
libelle_item->setToolTip(lines.at(i).libelle);
setDocumentMode(libelle_item);
libelle_item->setSizeHint(QSize(500,50));// <-does not seem to work
ui->operationTableWidget->setItem(i,1,libelle_item);
}
ui->operationTableWidget->resizeColumnsToContents();
ps: OperationLine is a simple class and .libelle is just a QString. Manualy resizing the column does not help. I also tried to disable editing and it does not help either. However if i comment my loop and manualy add item with QtCreator it seem to work as expected.

My original string contain return lines, removing them like:
QString s = lines.at(i).libelle;
s.replace('\n',' ');
ui->operationTableWidget->setItem(i,1,s);
is working.
As #Scheff'sCat pointed out in the comment of my original post, using the accepted solution at How to prevent too aggressive text elide in QTableview? work too and will display multiple lines withouts the dots in the wrong place.

Related

Trim text in a table column header with sort indicator

I have a table with styled column headers.
Header height is limited so the headers are actually narrow.
The header has also the sort indicator (the default arrow/triangle).
When the user changes the width of a column such that it is smaller than the text's width, the text is trimmed with 3 dots at the end. E.g. "Universi..."
So far so good.
The thing is the sort indicator hides part of the trimmed text.
Imagine wide column - the text is fully show and the sort icon is on the right and everthing looks good. Now the user resizes the column. Just before the text is trimmed with 3 dots, the sort indicator starts to hide the right side of the text. At some point the text is trimmed with the sort indicator on top of the 3 dots . E.g. "Universi.▽" or even "Univers▽".
It looks like the header does not take into account the sort sign.
Is there a simple way to set the sign indicator to not overlap the trimmed text e.g. "Univer... ▽"?
I need the columns to be resizable and sortable.
I don't want to define a special widget with push button and text box and handle events and trimming and so... it is a serious overhead.
Thanks
This is a bug https://bugreports.qt.io/browse/QTBUG-629
Which should be solved in Qt 5.4 https://codereview.qt-project.org/#/c/99900/

C++ Qt QTableWidget item moves when resizing column

I am writing a C++ plugin for an existing application where I need to display a window which contains a QTableWidget using Qt.
Here is an excerpt of my working code where I am building the QTableWidget and filling the cells.
tableWidget->setRowCount(0); // clear tablewidget
tableWidget->clearContents();
tableWidget->setColumnCount(5);
tableWidget->setRowCount(2);
QStringList header;
header << "Date" << "Owner" << "Type" << "Folder" << "Path";
tableWidget->verticalHeader()->setDefaultSectionSize(20);
tableWidget->setHorizontalHeaderLabels(header);
tableWidget->setItem(0,0,new QTableWidgetItem(QString("dog")));
tableWidget->setItem(0,1,new QTableWidgetItem(QString("cat")));
tableWidget->setItem(0,2,new QTableWidgetItem(QString("frog")));
tableWidget->setItem(1,0,new QTableWidgetItem(QString("shark")));
tableWidget->item(0,0)->setTextAlignment(Qt::AlignLeft);
tableWidget->item(0,1)->setTextAlignment(Qt::AlignLeft);
tableWidget->item(0,2)->setTextAlignment(Qt::AlignLeft);
tableWidget->resizeColumnsToContents();
It works as expected, except the data inside each successive column is moved further right than the previous column. This can be exaggerated when you resize a column and see the data in columns to the right "slide" even further right.
Here are 2 screenshots of the effect (before and after column resize). You can see how the words "cat" and "frog" have moved more to the right than normal.
What am I doing wrong? I want each cells text to be aligned to the left of each column.
The root of the problem appears to be related to Windows Display settings.
My laptop text display setting was set to "Medium - 125%".
When I set it back to "Smaller - 100%" then the problem went away.
I would still like my program to work properly if the user should use 125% text, but at least now I know the cause.
Does anyone know how I to prevent the above problem when using 125% text?

QListWidget, insert linebreak for longer text

I want to use QListWidget to display my content. But some of the content is quite long and I want to make the text continue on a second row instead of showing a horizontal scrollbar.
I use Qt Creator and I can't seem to find any options in the design view.
Enable word wrapping by calling
void setWordWrap ( bool on )
and set text elide mode to Qt::ElideNone
void setTextElideMode ( Qt::TextElideMode mode )
Also you may check that you didn't set too small maximum height for your items in the list.
P.S. Because you wrote about horizontal scrollbar, you definitely want to have multiline text in item, but not the item on multiple rows.

QTableView, select and shift+click

I have a small but quite annoying problem with Qt's QTableView
Since my view is used in a StackedLayout, I have to select a line based on a field in an other page (that part works ok).
So when I display this view, I select the line I want with a simple
QItemSelection selection = line2selection(line);
d_view->selectionModel()->select(selection, QItemSelectionModel::Select);
where line2selection creates a QItemSelection filled with all the indexes for the whole line.
As I sais, this part works ok, but introduce another problem:
When I do a shift+click to select several lines at once (which works great if I don't select a line "programatically"), it always stars the selection from the first line instead of the starting from the line currently selected.
Any idea how I could fix the problem?
btw, I tried to call the selectRow method on my view too, but doesn't seem to be much better...
add the QItemSelectionModel::Current flag to QItemSelectionModel::Select so the "current" item index is updated, this index acts as the anchor for the shift+click multi-selects

Notepad++ How do I insert a column of data?

So I am trying to take a column of text data and replace that data with edited information. I am trying to manipulate values in a fixed width file. I want to leave the rows intact. I know I can hold ALT and select a whole column of information but when I try to paste into the selected area Notepad++ just adds the information above the first row and deletes the column Ive selected. Please help, I have been researching for a while now and cant find anything on this.
Below I will try to explain a bit better, if I were to select the asterisks using Alt+mouse and I have a column of data that I have copied from another file how could I replace the asterisks but leave the other data intact?
1111122222**22233333333333
1111122222**22222223333333
1111111122**22222223333333
If I understand the question correctly, you have copied the column of data from somewhere else and want to copy it as a column into notepad++. If you simply select a column in your notepad++ document and try to replace it with the external column, you will get many copies of that column. The trick is to first paste your column into an empty document (or into new lines in an existing document), then select that column you just pasted in but make sure you select it in column mode, i.e., while holding down the Alt key, and then copy it with Ctrl-C. Now you can column-select the column you want to replace and copy in your copied column with Ctrl-V
You can use ALT + Mouse to select the columns to copy the data and replace it. This animated gif is self explanatory.
If I understand your question correctly, you want to paste a certain text in front of all columns you've selected ?
Either use ALT + Mouse or SHIFT + ALT + up/down arrow to select the desired number of columns.
Either use ALT + C or Menu Edit -> Column Editor to enter the Column Editor.
Fill in the "Text to Insert" and press Ok.
Good luck !
Edit: as pointed out in the comment, this is actually answered in Notepad++ How to paste string across multiple lines
ALT+Mouse works alright for me. I was able to replace the asterisks with other charactes. Maybe we have diferent versions? I don't think so, though.
Make sure you are also using Alt+Mouse when you select the information you want to copy. Not only when you paste it.
I hope that helps you.
Good luck!
Replacing a column with new data is easy:
Hold ALT + select with your mouse the column (you already did that)
Press DELETE or CTRL + X to remove the old column
Leave the cursor flickering in the same position (or wherever you want to add the new column)
Paste CTRL + V
Note: you must NOT have your column selected when pasting. I think that's what confused you.
Copy required text(columns) with Shift+alt and mouse (or arrows), then paste as required with ctrl+v.