我想在我QPushButton的另一边堆叠一些物体QMenuBar.
这就是我的窗口现在的样子:

这就是我希望它看起来的样子(我已经拍摄了图片):

我知道在motif小部件样式中,帮助菜单与右侧对齐,但我坚持plastique,所以这对我来说不是问题.
我正在使用Qt4.8.有任何想法吗?
在我的项目中,我有一些按钮在可见和不可见之间变换使用:
ui->button->setVisible(true);
//or
ui->button->setVisible(false);
Run Code Online (Sandbox Code Playgroud)
然而,似乎当它们看不见时,它们也不起作用?我怎么能绕过这个?
我已经尝试过了:
ui->button->setEnabled(true);
Run Code Online (Sandbox Code Playgroud)
对于他们所有人,但没有任何变化.
我最近转移到 Mac OS X 并注意到我的一个应用程序中的对话框看起来有点奇怪...我有几个对话框基本上是具有可配置路径的简单形式:
标签:<QLineEdit> <QPushButton (opens file dialog)>
标签: ...
对话框以 QGridLayout 组织,在 Ubuntu 上看起来不错:

在 Mac OS X 上,QPushButtons 行下方有一个很大的空白区域,这使得整个事情看起来很奇怪:

我发现这个错误报告显然已悄然关闭: https: //bugreports.qt.io/browse/QTBUG-2699
用户界面代码:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>431</width>
<height>235</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>PDF Export</string>
</property>
<property name="windowIcon">
<iconset resource="resources.qrc">
<normaloff>:/images/images/application-pdf.png</normaloff>:/images/images/application-pdf.png</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1">
<widget class="QLineEdit" name="texPath">
<property …Run Code Online (Sandbox Code Playgroud) 我有一个奇怪的问题.
我需要在QTableView中有一些按钮.我以前使用QAbstractItemView :: setIndexWidget()方法,但在处理大型模型时它不是很负责任.因此我决定切换到QStyledItemDelegate.我的按钮有图标(仅限图标,无文字).使用setIndexWidget时,我使用了以下代码:
ClientDetailsButton::ClientDetailsButton(const Client* _client,
QWidget* _parent) :
QPushButton("", _parent),
__current(_client) {
setIcon(QIcon(":/uiIcons/button-details.png"));
}
Run Code Online (Sandbox Code Playgroud)
而且效果很好.但是当我切换到委托时,我会这样使用它:
QStyleOptionButton button;
button.rect = _option.rect;
button.text.clear();
button.icon = QIcon(":/uiIcons/button-details.png");
button.state = _option.state | QStyle::State_Enabled;
if (_index == __button)
button.state |= QStyle::State_Sunken;
QApplication::style()->drawControl(QStyle::CE_PushButton, &button, _painter);
Run Code Online (Sandbox Code Playgroud)
按钮本身很好,但它是空的.没有可见的图标.令人惊讶的是,当我使用时,例如:
button.icon = QIcon::fromTheme("dialog-information", QIcon(":/uiIcons/button-details.png"));
Run Code Online (Sandbox Code Playgroud)
主题图标可见.但如果Qt找不到主题图标,则替换仍然是空白.我尝试了所有我能想到的东西,并且不知道为什么它不起作用.有人有什么想法吗?
我在创建带有信号和插槽的 QPushButton 时遇到问题。首先,我创建了一个类,其中插槽:
class A : public QWidget{
public slots:
void handleButton();
};
Run Code Online (Sandbox Code Playgroud)
有我的 handleButton 功能:在 .cpp 中
void A::handleButton(int row, int col){
m_button->setText("Example");
// resize button
m_button->resize(100,100);
}
Run Code Online (Sandbox Code Playgroud)
然后我想连接按钮。
QObject::connect(m_button, SIGNAL(clicked()),qApp, SLOT(handleButton()));
Run Code Online (Sandbox Code Playgroud)
但是当我启动应用程序时出现错误:“没有这样的插槽”有人可以帮助我吗?
我开始学习 Python 和 PyQt。目前,我正在解决一个关于连接信号和插槽的非常基本的问题,使用从 QDesigner 生成的对话框表单。我想从 QDialog 连接一个按钮。该代码不会产生错误。正如预期的那样,对话框显示出来。但是点击按钮没有任何反应。
或者,我尝试将代码表单Ui_Dialog直接包含在我的目标类中Testdialog。然后连接正常工作。似乎我在从Ui_DialogtoTestdialog和/或我想要执行对话框的方式继承属性时犯了一个错误。
我的主程序如下所示:
from __future__ import unicode_literals
import sys
from PyQt4 import *
from PyQt4 import QtGui
from PyQt4.QtCore import SIGNAL, QObject
import UI_Test
class Testdialog(QtGui.QDialog, UI_Test.Ui_Dialog):
def __init__(self,parent=None):
super(Testdialog, self).__init__(parent)
self.setupUi(self)
print("Connect buttons") # gives the expected output
self.connect(self.pushButton_Ok, SIGNAL("clicked()"), self.clickedOk)
self.connect(self.pushButton_Cancel, SIGNAL("clicked()"), self.clickedCancel)
# Alternativly I have tríed the following without improvement:
# self.pushButton_Ok.clicked.connect(self.clickedOk)
# QObject.connect(self.pushButton_Cancel, SIGNAL("clicked()"), self.clickedCancel)
def clickedCancel(self):
print ("Cancel") # …Run Code Online (Sandbox Code Playgroud) 我正在为Qt按钮小部件编写一个弹出菜单.只要单击按钮,就会弹出一个菜单(按钮下方).
默认情况下,弹出菜单位于左下方.
有没有办法让弹出菜单弹出按钮右下方的右侧?
没有设定位置功能,所以我想知道是否有一些复杂的方法呢?
这是一些代码(用于弹出菜单):
QMenu *menuMode = new QMenu(this);
min = menu ->addAction("In");
mout = menu ->addAction("out");
ui->pushButtonMode->setMenu(menuMode); //I am writing in MainWindow, that's there is ui
Run Code Online (Sandbox Code Playgroud) 我在 QT Creator 中有一个项目,我希望在使用新对象时自动包含头文件。这就像在 Eclipse 中:在使用 Ctrl+Alt+Space 调用新对象时添加所需的标题:将包含所有需要的标题。
这是一个例子
#include <QApplication>
#include <QPushButton> /* Header that i want to include automatically */
int main( int argc, char *argv[ ] )
{
QApplication app( argc, argv) ;
QWidget fenetre;
/*Add needed headers when invoking a new object like ctrl+alt+space in eclipse*/
QPushButton bouton( "Bonjour", &fenetre) ;
bouton. move(70,60);
fenetre. show( ) ;
return app. exec( ) ;
}
Run Code Online (Sandbox Code Playgroud)
关于如何在 QT Creator 中执行此操作的任何建议?谢谢
我想弄清楚如何通过按下另一个 QPushbutton 来创建 QPushButton,以便我最终可以动态创建按钮。似乎创建按钮的初始方法在函数中不起作用。
import sys
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtWidgets import QMainWindow, QLabel, QGridLayout, QWidget
from PyQt5.QtWidgets import QPushButton
from PyQt5.QtCore import QSize
class MainWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.setMinimumSize(QSize(300, 200))
pybutton = QPushButton('Create a button', self)
pybutton.clicked.connect(self.clickMethod)
pybutton.resize(100,100)
pybutton.move(100, 100)
def clickMethod(self):
print('Clicked')
newBtn = QPushButton('New Button', self)
newBtn.move(0, 0)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
mainWin = MainWindow()
mainWin.show()
sys.exit( app.exec_() )
Run Code Online (Sandbox Code Playgroud) 假设我有一个带有许多 QGroupBox 的应用程序,如下所示:
import sys
from PyQt4 import QtGui, QtCore
class Main(QtGui.QWidget):
# pylint: disable=too-many-statements
def __init__(self, main):
super(Main, self).__init__()
self.grid_layout = QtGui.QGridLayout()
self.line_edit = QtGui.QLineEdit()
self.grid_layout.addWidget(self.create_settings_group(), 0, 0, 2, 1)
self.push_button = QtGui.QPushButton("go", self)
self.grid_layout.addWidget(self.create_controls_group(), 0, 1)
self.setLayout(self.grid_layout)
main.setCentralWidget(self)
def create_settings_group(self):
group_box_settings = QtGui.QGroupBox(self)
group_box_settings.setTitle("group1")
grid = QtGui.QGridLayout()
grid.addWidget(self.line_edit, 0, 0)
group_box_settings.setLayout(grid)
return group_box_settings
def create_controls_group(self):
group_box_settings = QtGui.QGroupBox(self)
group_box_settings.setTitle("group2")
grid = QtGui.QGridLayout()
grid.addWidget(self.push_button, 0, 0, 1, 2)
group_box_settings.setLayout(grid)
return group_box_settings
class GUI(QtGui.QMainWindow):
def __init__(self):
super(GUI, self).__init__()
self.ui = …Run Code Online (Sandbox Code Playgroud)