QListWidget, insert linebreak for longer text - c++

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.

Related

QTableWidgetItem displays three dots instead of full text

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.

Remove space between Oracle APEX page items

I have created two APEX checkbox items on top of each other, one being the checkbox selections (complete, incomplete) and one being a select all option above it (with associated JavaScript to enable the select all functionality). Everything works great, but I am trying to remove the white space in between the page items.
The checkbox item with the selections has no label because the Select All item has the heading for both items to be treated as "one item" to the user. I think the template might still be accounting for the label padding, but I'm not sure.
Does anyone know a solution in order to remove the white space (I'd be find with a small amount of white space but right now it is very large and doesn't look visually appealing.
Open up the template options, and set the desired margin attributes to 'None'

Change label of QComboxBox without using lineEdit

Currently I want to implement a widget to allow user to enable/disbale all provided options of a QSet. So i took a combobox and added selectable items. So far so good, but how I can change text displayed in combobox? Currently all my items have just ItemIsUserCheckable and ItemIsEnabled as enabled flags (ItemIsSelectable is not enabled), so text of ComboBox is always text of first item. Instead I want as text "Flag1, Flag 3, Flag6" if there multiple flags and user enabled Flag 1, 3 and 6. But setCurrentText and setEditText requiring setEditable(true) or an custom lineEdit. But using an lineEdit is changing appearance. So is there another way?
I had a similar problem a while back, I ended up 'solving' it by adding an extra item to my model that was first in the list and always set as the current item. I then updated it's text to say 'Select items...' or 'X item(s) selected' as appropriate.

interactivly resizable rows in QListWidget

In a QTableWidget I can configure the rows to be resizable by the user on run time by setting the verticalHeader's resizeMode to Interactive like this:
table.verticalHeader().setResizeMode(QtGui.QHeaderView.Interactive)
How would I configure a similar behavior for QListWidget? Unfortunately the QListWidget resizeMode does not have an Interactive item and I haven't found anything similar.
The best would be to configure it for the whole list but when it's possible for single rows/items that would be ok, too.
As doc said:
This view does not display horizontal or vertical headers; to display
a list of items with a horizontal header, use QTreeView instead.
So you should use QTreeView (or QTreeWidget) with one column and maybe with specific style.
Another approach. There are no header, so you can provide some instrument (dialog window, slider or something else) where user will be able to change row height, to change row height you should just use setData() and set QSize() to Qt::SizeHintRole. For example:
ui->listWidget->model()->setData(ui->listWidget->currentIndex(),
QSize(40,40),Qt::SizeHintRole);

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