任何人都可以告诉我为什么我可以看到QTableView
的滚动条,但无法使用它吗?
有人有想法吗?
我的代码:
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);
}
我忘了什么吗?
答案 0 :(得分:0)
你有一堆互相重叠的小部件。我建议使用布局,这样你就不会遇到这样的问题。
但主要问题是你的QWidget *mywidget
对象。您没有为其设置几何图形,因此最终会覆盖QTableView
。例如,如果您使用红色背景设置样式表,您将看到发生这种情况。