1 Attachment(s)
QListWidgetItem doesn't select
Ok,
I'm encountering a problem with the QListWidget and QListWidgetItem. Specifically, the first list widget item can't be selected if I click on the item text. If, however, I click on the blank space to it's right, I can select it just fine. The second item I can select regardless of where I click. What boggles me is that both items are constructed using the same code, so it doesn't seem to be a problem with anything I'm doing.
I'm using Qt 4.8.5, and no, upgrading to 5.x isn't an option, in case someone suggests it. :)
Here's a marked up screenshot illustrating the problem:
Attachment 9855
And the relevant construction code:
Code:
UserSettingsDialog
::UserSettingsDialog(QMainWindow *parent
) :{
setWindowTitle
(QString::fromUtf8 ("User Settings"));
createPage ("Display Format");
createPage ("Window Size");
connect (mListWidget,
this,
}
Code:
void UserSettingsDialog
::createPage (const QString &pageName
) {
SettingPage *page = new SettingPage (pageName,
CSMSettings::UserSettings::instance().settingModel(), false, this);
mStackedWidget->addWidget (&dynamic_cast<QWidget &>(*(page->pageFrame())));
//////////////////////////////////
// QListWidget item constructed and added to the list widget here
//finishing touches
int textWidth = fm.width(page->objectName());
mListWidget->setMinimumWidth(textWidth + 50);
resize (mStackedWidget->sizeHint());
}
Re: QListWidgetItem doesn't select
Nothing in your code snippets has anything to do with selection of an item or items in the list. If you mean selection then you need to show how you have configured the selectionMode() and are determining that the item is not selected.
If you mean by "can't be selected" that the currentItemChanged() is not emitted if you click on the first row then, in all likelihood it is because the first row is already the current item. The changed signal is only emitted if the current index changes.
Re: QListWidgetItem doesn't select
Quote:
Nothing in your code snippets has anything to do with selection of an item or items in the list. If you mean selection then you need to show how you have configured the selectionMode() and are determining that the item is not selected.
Err.. I used the QListWidget, not QListView. That means I'm relying on the internal models that the QListWidget class provides. I do nothing more than populate the QListWidget with two QListWidgetItems and listen for an index change.
Quote:
If you mean by "can't be selected" that the currentItemChanged() is not emitted if you click on the first row then, in all likelihood it is because the first row is already the current item. The changed signal is only emitted if the current index changes.
You're right that the currentItemChanged() signal is not emitted, but only if I click on the text of the first QListWidgetItem. If I click on the same row, but to the right of the text, the first item *is* selected. Seems like there are two columns/indices at play, but I don't know why that would be.
Anyway, given that I've not done anything unique and I'm using the default implementation of QListWidget, the behavior just doesn't make sense to me.
I did try explicitly setting the selection behavior to both SelectRows and SelectItems. Neither case had any effect on the problem.
Re: QListWidgetItem doesn't select
Quote:
Err.. I used the QListWidget, not QListView
QListWidget is a QListView.
Both have a current item and zero or more selected items: the two lists are not necessarily related. The list has a current item even if selectionMode() == QAbstractItemView::NoSelection.
You seem to be talking about the selection but meaning the current item.
The current item is subtly indicated by a dotted outline around or underline on the cell text (which is black text on white typically unless it also in the selected items). With a populated list like my example the first item is the current item but the selection is empty at start. In the default state the selection will follow actions that affect the current item. Changing the current row by clicking or keyboard will change both the current row and selection. If you want the first item to be in the selection by default simply do that explicitly.
When you click in the blank area of the first row you are adding the clicked row to the selection. It then becomes highlighted, usually with white text on dark background. I assume this is what you mean by "it works". It works regardless of where I click on the item on my KDE desktop with the default Qt4 style. I cannot tell what style or Window manager you are using, but that might well be playing into this apparent behaviour.
Code:
#include <QtGui>
{
Q_OBJECT
public:
for (int i = 0; i < 5; ++i)
addItem
(QString("Item %1").
arg(i
));
qDebug() << Q_FUNC_INFO << "Current row:" << currentRow() << "Current selection:" << selectedItems();
connect(this,
SLOT(showChange()));
}
public slots:
void showChange() {
qDebug() << Q_FUNC_INFO << "Current row:" << currentRow() << "Current selection:" << selectedItems();
}
};
int main(int argc, char **argv)
{
List list;
list.show();
return app.exec();
}
#include "main.moc"
Re: QListWidgetItem doesn't select
Code:
It works regardless of where I click on the item on my KDE desktop with the default Qt4 style. I cannot tell what style or Window manager you are using, but that might well be playing into this apparent behaviour.
The window manager may be the problem. I'm using Mint 16 with Cinnamon, which has a troubled performance record in my experience. Thought I'd give it another chance when I upgraded...
Re: QListWidgetItem doesn't select
Thanks for the post anyway. It will be useful to me, guess so.