简体   繁体   English

我怎样才能一个接一个地放置多个 QToolButton,而不是一个放在另一个下面

[英]How can I place multiple QToolButton one after the other, instead of being one below the other

I am working on a QT project that makes it possible to view and edit table views from a given file.我正在从事一个 QT 项目,该项目可以查看和编辑来自给定文件的表格视图。 For the buttons in the GUI I'm using QToolButton, but when more than one button is created, they are placed one below the other, whereas I would like them all to be shown one after the other on the same row.对于 GUI 中的按钮,我使用的是 QToolButton,但是当创建了多个按钮时,它们会一个接一个地放置,而我希望它们在同一行中一个接一个地显示。 Here is the code for the two buttons:这是两个按钮的代码:

QToolButton* newFileButton = new QToolButton(this);  
newFileButton -> setIcon(QIcon(":/images/newFile.svg"));
newFileButton -> setIconSize(QSize(44, 44));
newFileButton -> setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
newFileButton -> setText("New File");

QToolButton* openFileButton = new QToolButton(this);
openFileButton -> setIcon(QIcon(":/images/openFile.svg"));
openFileButton -> setIconSize(QSize(44, 44));
openFileButton -> setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
openFileButton -> setText("Open");

This is what I get:这就是我得到的:

这些按钮一个位于另一个下方

How can I place them one after the other?我怎样才能一个接一个地放置它们? Thanks谢谢

Put them in a horizontal layout or a widget with horizontal layout.将它们放在水平布局或具有水平布局的小部件中。 You can also use a grid layout for your window and make the table span all columns.您还可以为 window 使用网格布局,并使表格跨越所有列。

There is also the QButtonBox that has a number of default buttons with default icons that might mesh better with the users theme.还有 QButtonBox,它有许多带有默认图标的默认按钮,可以更好地适应用户主题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM