gpt4 book ai didi

c++ - 滚动条Qt,无法滚动

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:50:58 25 4
gpt4 key购买 nike

谁能告诉我为什么我可以从我的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);

}

我是不是忘记了什么?

最佳答案

您有一堆相互重叠的小部件。我建议使用布局,这样你就不会遇到这样的问题。

但主要问题是您的 QWidget *mywidget 对象。您没有为其设置几何图形,因此它最终覆盖了您的 QTableView。例如,如果您将样式表设置为红色背景,您就会看到这种情况发生。

关于c++ - 滚动条Qt,无法滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25403269/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com