qt4

How to insert a button inside a QLineEdit

人盡茶涼 提交于 2019-12-17 18:47:15
问题 I need help inserting a button inside in a QLineEdit that can call a function. For example, like this google image: 回答1: Below is a nearly direct translation of the Qt code from here. Differences: button is always visible clicking on the button emits buttonClicked(bool) signal Code: from PyQt4 import QtGui, QtCore class ButtonLineEdit(QtGui.QLineEdit): buttonClicked = QtCore.pyqtSignal(bool) def __init__(self, icon_file, parent=None): super(ButtonLineEdit, self).__init__(parent) self.button =

PyQt sending parameter to slot when connecting to a signal

北战南征 提交于 2019-12-17 17:55:11
问题 I have a taskbar menu that when clicked is connected to a slot that gets the trigger event. Now the problem is that I want to know which menu item was clicked, but I don't know how to send that information to the function connected to. Here is the used to connect the action to the function: QtCore.QObject.connect(menuAction, 'triggered()', menuClickedFunc) I know that some events return a value, but triggered() doesn't. So how do I make this happen? Do I have to make my own signal? 回答1: Use a

Unit and functional testing a PySide-based application?

空扰寡人 提交于 2019-12-17 17:32:17
问题 I'm building a PySide 1.1.0-based application, and have been looking for good examples to look at for unit and functional testing my application. I want to be able to do functional testing of the UI (simulating clicks, key presses, etc), unit testing of UI slots that alter the layout of the UI (presumably using a partially-mocked sender and receiver), as well as unit testing of code that involves widgets, but without requiring any windows to be rendered. As one example, I dynamically create

Qt 4: Move window without title bar

坚强是说给别人听的谎言 提交于 2019-12-17 16:23:18
问题 I have a Qt::Popup flagged window (which does not have a title bar and close etc buttons) and would like to move by dragging\clicking on the non-title bar area.... On Win32, the solution could be WM_NCLBUTTONDOWN but my requirement is crossplatform. 回答1: Try this to move the window manually: void PopupWindow::mousePressEvent(QMouseEvent *event){ mpos = event->pos(); } void PopupWindow::mouseMoveEvent(QMouseEvent *event){ if (event->buttons() & Qt::LeftButton) { QPoint diff = event->pos() -

ComboBox of CheckBoxes?

倾然丶 夕夏残阳落幕 提交于 2019-12-17 16:07:09
问题 I am trying to make the items in a ComboBox checkable. I tried this: http://programmingexamples.net/wiki/Qt/ModelView/ComboBoxOfCheckBoxes where I subclassed QStandardItemModel and re-implemented the flags() function to make the items checkable. Then I added this model to the ComboBox . Unfortunately, a checkbox does not appear with the items. Can anyone see where I have gone wrong? 回答1: Have you set a check state as well as making them checkable? In my example below, this line is critical:

Identifier for win64 configuration in Qmake

五迷三道 提交于 2019-12-17 15:54:21
问题 Is there a "win64" identifier in Qmake project files? Qt Qmake advanced documentation does not mention other than unix / macx / win32. So far I've tried using: win32:message("using win32") win64:message("using win64") amd64:message("using amd64") The result is always "using win32". Must I use a separate project-file for x32 and x64 projects, so they would compile against correct libraries? Is there any other way to identify between 32-bit and 64-bit environments? 回答1: I do it like this win32

Console output in a Qt GUI app?

一笑奈何 提交于 2019-12-17 06:06:10
问题 I have a Qt GUI application running on Windows that allows command-line options to be passed and under some circumstances I want to output a message to the console and then quit, for example: int main(int argc, char *argv[]) { QApplication a(argc, argv); if (someCommandLineParam) { std::cout << "Hello, world!"; return 0; } MainWindow w; w.show(); return a.exec(); } However, the console messages do not appear when I run the app from a command-prompt. Does anyone know how I can get this to work

Qt: resizing a QLabel containing a QPixmap while keeping its aspect ratio

帅比萌擦擦* 提交于 2019-12-17 05:41:15
问题 I use a QLabel to display the content of a bigger, dynamically changing QPixmap to the user. It would be nice to make this label smaller/larger depending on the space available. The screen size is not always as big as the QPixmap. How can I modify the QSizePolicy and sizeHint() of the QLabel to resize the QPixmap while keeping the aspect ratio of the original QPixmap? I can't modify sizeHint() of the QLabel, setting the minimumSize() to zero does not help. Setting hasScaledContents() on the

Serialization with Qt

て烟熏妆下的殇ゞ 提交于 2019-12-17 02:28:32
问题 I am programming a GUI with Qt library. In my GUI I have a huge std::map. "MyType" is a class that has different kinds of fields. I want to serialize the std::map. How can I do that? Does Qt provides us with neccesary features? 回答1: QDataStream handles a variety of C++ and Qt data types. The complete list is available at http://doc.qt.io/qt-4.8/datastreamformat.html. We can also add support for our own custom types by overloading the << and >> operators. Here's the definition of a custom data

OS X transparent panels in Qt?

拜拜、爱过 提交于 2019-12-14 04:27:18
问题 Is there a way to create a transparent panel as described by the Apple Human Interface Guidelines in Qt 4.6 (built for OS X 10.6/Cocoa)? If not, are there any alternatives similar in look and function? I understand that Qt is a cross platform toolkit, but I want my application to feel as "native" as possible. 回答1: I haven't tried on Mac, but this should be possible. Here's what the QWidget docs say: Creating Translucent Windows Since Qt 4.5, it has been possible to create windows with