Answer the question
In order to leave comments, you need to log in
Why in the QTabWidget widget does not show the list of strings in the QListView widget?
Good afternoon!
There was such a problem: QListView items are not displayed if it is in a QTabWidget widget
//Заголовочные файлы
#ifndef TABUDOBR_H
#define TABUDOBR_H
#include <QtWidgets>
class TabUdobr : public QWidget
{
Q_OBJECT
private:
QListView* pListView;
public:
explicit TabUdobr(QWidget *parent = nullptr);
signals:
public slots:
};
#endif // TABUDOBR_H
#ifndef TABCOOKING_H
#define TABCOOKING_H
#include <QtWidgets>
class TabCooking : public QWidget
{
Q_OBJECT
private:
QLabel* plabel;
public:
explicit TabCooking(QWidget *parent = nullptr);
signals:
public slots:
};
#endif // TABCOOKING_H
TabUdobr::TabUdobr(QWidget *parent) : QWidget(parent)
{
pListView = new QListView;
QVBoxLayout* playout = new QVBoxLayout;
QStringListModel model;
model.setStringList(QStringList() << "Item1" << "Item2" << "Item3");
QItemSelectionModel itemselect(&model);
pListView->setModel(&model);
pListView->setSelectionModel(&itemselect);
playout->addWidget(pListView);
setLayout(playout);
}
//main.cpp
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget mainWindow;
QTabWidget* pbar = new QTabWidget;
QVBoxLayout* pvboxlay = new QVBoxLayout;
pbar->addTab(new TabUdobr, "TestTab");
pvboxlay->addWidget(pbar);
pvboxlay->addWidget(new TabUdobr);
mainWindow.setLayout(pvboxlay);
mainWindow.show();
return a.exec();
}
//main.cpp
QListView* pListView = new QListView;
QVBoxLayout* playout = new QVBoxLayout;
QStringListModel model;
model.setStringList(QStringList() << "Item1" << "Item2" << "Item3");
QItemSelectionModel itemselect(&model);
pListView->setModel(&model);
pListView->setSelectionModel(&itemselect);
playout->addWidget(pListView);
mainWindow.setLayout(playout);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question