Qt scroll bar, cannot scroll

Can someone tell me why I see the scrollbar from my QTableView but can't use it? Does anyone have an idea?

My code is:

 View::View() { } void View::init() { // add model and Table myModel= new Model(); QTableView *myView=new QTableView( this ); myView->setModel(myModel); QWidget *mywidget= new QWidget(this); // add buttons and labels QPushButton* btnaddtotable = new QPushButton( "Add to Table",this); btnaddtotable->setGeometry(50,20,100,40); QPushButton* btnFile = new QPushButton( "Open file",this); btnFile->setGeometry(50,20,100,40); QPushButton* btnOpenFile = new QPushButton( "Search file",this); btnFile->setGeometry(50,20,100,40); btnOpenFile->setGeometry(50,20,100,40); // connections QObject::connect ( btnaddtotable, SIGNAL ( clicked() ), this , SLOT(pushButtonClicked())) ; QObject::connect ( btnFile, SIGNAL ( clicked() ), this , SLOT(FileButtonClicked())) ; QObject::connect ( btnOpenFile, SIGNAL ( clicked() ), this , SLOT(OpenFileButtonClicked())); // named the buttons and labels myView->setObjectName(QStringLiteral("Table")); myView->setGeometry(QRect(20, 100, 361, 191)); txtname = new QLineEdit(mywidget); txtname->setObjectName(QStringLiteral("txtname")); txtname->setGeometry(QRect(20, 30, 151, 31)); txtvalue = new QLineEdit(mywidget); txtvalue->setObjectName(QStringLiteral("textEdit")); txtvalue->setGeometry(QRect(230, 30, 151, 31)); label = new QLabel ("Name: ", mywidget ); label->setObjectName(QStringLiteral("label")); label->setGeometry(QRect(20, 10, 61, 20)); label_2 = new QLabel ("Value ", mywidget ); label_2->setObjectName(QStringLiteral("label_2")); label_2->setGeometry(QRect(235, 10, 51, 20)); QLabel *label3 = new QLabel ("DateiPfad: ", mywidget ); label3->setObjectName(QStringLiteral("label")); label3->setGeometry(QRect(20, 305, 61, 20)); txtPfad = new QLineEdit(mywidget); txtPfad->setObjectName(QStringLiteral("txtPfad")); txtPfad->setGeometry(QRect(80, 300, 300, 31)); btnaddtotable->setObjectName(QStringLiteral("pushButton")); btnaddtotable->setGeometry(QRect(240, 70, 75, 23)); btnFile->setGeometry(QRect(160, 70, 75, 23)); btnOpenFile->setGeometry(QRect(80, 70, 75, 23)); // searching the strings this->setGeometry(500,500,400,350); // for sorting sort_filter = new QSortFilterProxyModel(this); sort_filter->setSourceModel(myModel); // sort the first column sort_filter->sort(0); myView->setColumnWidth(0,179); myView->setColumnWidth(1,180); myView->setModel (sort_filter); // to check if exists sort_filter->setSourceModel(myModel); //myView->setCornerButtonEnabled(true); //myView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); myView->setAutoScroll(true); myView->setAutoScrollMargin(20); myView->setHorizontalScrollMode(QAbstractItemView::ScrollPerItem); } 

Did I forget something?

+5
source share
1 answer

You have a mess of widgets that overlap. I would suggest using layouts so that you don't have such problems.

But the main problem is your QWidget *mywidget . You do not give it geometry, so it ends on your QTableView . If you set a style sheet for it with a red background, for example, you will see that this happens.

0
source

Source: https://habr.com/ru/post/1200743/


All Articles