QPushButton删除空间(Jambi)

时间:2016-04-20 18:55:33

标签: java qt qt-jambi jambi

如何删除QGridLayout的差距/空格?

我在看Windows 10计算器,它是:

enter image description here

你可以看到按钮7和8之间没有空格,我尝试在Jambi中做同样的事情,设置QPushButtonQVBoxLayout main_layout = new QVBoxLayout(); QGridLayout sample_layout = new QGridLayout(); sample_layout.setHorizontalSpacing(0); sample_layout.setVerticalSpacing(0); sample_layout.setContentsMargins(0,0,0,0); sample_layout.setSpacing(0); sample_layout.setWidgetSpacing(0); main_layout.addLayout(sample_layout); QLineEdit edit_input = new QLineEdit(); QPushButton action_0 = new QPushButton("0"); action_0.setMinimumHeight(60); action_0.setContentsMargins(0, 0, 0, 0); QPushButton action_1 = new QPushButton("1"); action_1.setMinimumHeight(60); action_1.setContentsMargins(0, 0, 0, 0); QPushButton action_2 = new QPushButton("2"); action_2.setMinimumHeight(60); action_2.setContentsMargins(0, 0, 0, 0); QPushButton action_3 = new QPushButton("3"); action_3.setMinimumHeight(60); action_3.setContentsMargins(0, 0, 0, 0); QPushButton action_4 = new QPushButton("4"); action_4.setMinimumHeight(60); action_4.setContentsMargins(0, 0, 0, 0); QPushButton action_5 = new QPushButton("5"); action_5.setMinimumHeight(60); action_5.setContentsMargins(0, 0, 0, 0); QPushButton action_6 = new QPushButton("6"); action_6.setMinimumHeight(60); action_6.setContentsMargins(0, 0, 0, 0); QPushButton action_7 = new QPushButton("7"); action_7.setMinimumHeight(60); action_7.setContentsMargins(0, 0, 0, 0); QPushButton action_8 = new QPushButton("8"); action_8.setMinimumHeight(60); action_8.setContentsMargins(0, 0, 0, 0); QPushButton action_9 = new QPushButton("9"); action_9.setMinimumHeight(60); action_9.setContentsMargins(0, 0, 0, 0); QPushButton action_plus = new QPushButton("+"); action_plus.setMinimumHeight(120); action_plus.setContentsMargins(0, 0, 0, 0); QPushButton action_minus = new QPushButton("-"); action_minus.setMinimumHeight(60); action_minus.setContentsMargins(0, 0, 0, 0); QPushButton action_divide = new QPushButton("/"); action_divide.setMinimumHeight(60); action_divide.setContentsMargins(0, 0, 0, 0); QPushButton action_times = new QPushButton("X"); action_times.setMinimumHeight(60); action_times.setContentsMargins(0, 0, 0, 0); QPushButton action_equal = new QPushButton("="); action_equal.setMinimumHeight(120); action_equal.setContentsMargins(0, 0, 0, 0); QPushButton action_dot = new QPushButton("."); action_dot.setMinimumHeight(60); action_dot.setContentsMargins(0, 0, 0, 0); QPushButton action_del = new QPushButton("< Delete"); action_del.setMinimumHeight(60); action_del.setContentsMargins(0, 0, 0, 0); QPushButton action_clear = new QPushButton("Clear"); action_clear.setMinimumHeight(60); action_clear.setContentsMargins(0, 0, 0, 0); sample_layout.addWidget(edit_input,0,0,1,4); sample_layout.addWidget(action_minus,1,0); sample_layout.addWidget(action_divide,1,1); sample_layout.addWidget(action_times,1,2); sample_layout.addWidget(action_del,1,3); sample_layout.addWidget(action_7,2,0); sample_layout.addWidget(action_8,2,1); sample_layout.addWidget(action_9,2,2); sample_layout.addWidget(action_4,3,0); sample_layout.addWidget(action_5,3,1); sample_layout.addWidget(action_6,3,2); sample_layout.addWidget(action_1,4,0); sample_layout.addWidget(action_2,4,1); sample_layout.addWidget(action_3,4,2); sample_layout.addWidget(action_clear,5,0); sample_layout.addWidget(action_0,5,1); sample_layout.addWidget(action_dot,5,2); sample_layout.addWidget(action_plus,2,3,2,1); sample_layout.addWidget(action_equal,4,3,2,1); 的空间如下:

main_layout.setContentsMargins(0,0,0,0)

但我之间仍然存在差距。

enter image description here

注意:如果我设置main_layout.setWidgetSpacing(0)QLineEdit我完全适合QPushButton下面的图片,但不是QPushButton,所以我相信setContentsMargins()中有一个选项1}}创造了这个差距,但只有QPushButton QSpacerItem的选项,任何想法?

enter image description here

我确实调查过那些提出同样问题的人,他们使用QLineEdit解决方案没有意义(感觉不是正确/专业的方式),导致QPushButton它确实完全没有任何差距,但不在action_plus.setFlat(true);

修改:当我申请<script> Dropzone.options.mediaUploader= { init: function () { this.options.uploadMultiple = false; this.on("success", function (file, responseText) { alert("Wheeeee!"); }); } }; </script> <div id="dropzone"> <form id="mediaUploader" action="/api/MediaUploader/upload" class="dropzone needsclick dz-clickable"> <!-- inputs --> <input type="text" name="Title" id="Title" placeholder="Title" /> <input type="text" name="Description" id="Description"/> <div class="dz-message needsclick"> <h2>Drop file here or click to upload.</h2><br> </div> </form> </div> 时,按钮结果看起来很相似:

enter image description here

1 个答案:

答案 0 :(得分:1)

为了避免大量编写,请创建一个继承自QPushButton的自定义类。在构造函数内部添加一个调用setFlat(true),用于处理按钮边框的抬起(除非用样式覆盖)。下面的样式表(使用setStyleSheet(...)设置按钮来使用它)可以产生漂亮的悬停效果:

QPushButton:hover{
  background-color: rgb(164, 156, 156);
  border: 0px;
}

根据您的喜好更改颜色以适合Windows 10主题。您可以省略setFlat(true),而是添加

QPushButton{
  border: 0px
}

到样式表(以及悬停处理程序)。效果是一样的。

结果是(在我的情况下是Linux):

enter image description here

您还可以使用样式表中的QLineEdit属性展平border

根本没有边框:

enter image description here

1px实线边框:

enter image description here