我想在Qt中创建一个具有以下功能的自定义小部件:
为了提供一个想法,这里是一个类似的小部件(而不是Qt)的图像:

我已经有一个正常工作的框架,并在QDesigner中公开.我现在需要让它扩展/崩溃,这似乎并不那么简单.
我尝试使用resize(),sizePolicy(),sizeHint(),但这不起作用:当框架折叠时,我得到以下值:
sizeHint: (500,20)
size : (500,20)
closestAcceptableSize: (518,150)
Painted size: (518, 150)
Run Code Online (Sandbox Code Playgroud)
QLayout :: closestAcceptableSize不是小部件的一部分,因此我无法更改它.
任何提示或/和代码片段来实现这一点?
编辑:这是一个简单的例子.除了必要的我删除了所有.
main.cpp示例
#include <QWidget>
#include <QPushButton>
#include <QVBoxLayout>
#include "section.hpp"
using namespace myWidgets;
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
// Create the main Window
QWidget window;
window.resize(500,500);
window.setStyleSheet("QPushButton:{background-color:rgba(128,128,128,192);}");
// Create the main window layout
QVBoxLayout topLayout(&window);
QWidget *w1 = new QWidget();
w1->setStyleSheet("background-color:rgba(128,128,128,192);");
topLayout.addWidget(w1);
Section section(&window);
topLayout.addWidget(§ion);
QVBoxLayout inLayout(§ion);
QPushButton *button = …Run Code Online (Sandbox Code Playgroud) 我有一个QTableView3 行 2 列。(这里我使用的是QStandardItemModel)。我想在单击 QPushButton 时向上/向下移动一行。如何在 中向上/向下移动一行QTableView?
感谢您的回复 vahancho。我已经尝试使用QAbstractItemModel::moveRow,但它不起作用:
int currentRow = ui->tableView->currentIndex().row();
QModelIndex sourceParent = ui->tableView->model()->index(ui->tableView->selectionModel()->currentIndex().row(),0);
QModelIndex destinationParent = ui->tableView->model()->index(ui->tableView->selectionModel()->currentIndex().row()+1,0);
ui->tableView->model()->moveRow(sourceParent,currentRow, destinationParent,destinationParent.row());
Run Code Online (Sandbox Code Playgroud)