qtgui

How to get the mouse position on the screen in Qt?

不羁的心 提交于 2019-12-08 17:41:46
问题 I want to get the mouse coordinates on the screen. How can I do this in Qt? On Windows, using C# I was doing something like suggested in the answers to this question. 回答1: As the docs state: - QCursor::pos() Returns the position of the cursor (hot spot) of the primary screen in global screen coordinates. If you have multiple screens, you can use: - QPoint QCursor::pos(const QScreen * screen) Note that QScreen is for Qt 5 回答2: Try this : QCursor::pos() should work perfectly 来源: https:/

How to customize QTableWidget through stylesheet?

跟風遠走 提交于 2019-12-08 11:23:05
问题 I'm trying to customize a QTableWidget through stylesheet and I'm only limited to the items descibed here. How do I change the spacing in the horizontal header of the table, the size of its header label, the spaces between the columns, et al? 回答1: You should use QAbstractItemDelegate to control display of items in QTableWidget. From explanation of delegates: "Unlike the Model-View-Controller pattern, the model/view design does not include a completely separate component for managing

Accessing dynamically added widgets (pyqt)

给你一囗甜甜゛ 提交于 2019-12-08 04:35:52
问题 I want add text into a text box which I've added using a push button based on the accepted answer for this question : Dynamically adding and removing widgets in pyqt My problem however is that I cannot access the text boxes I've added. This post tells me that I can use itemAt() to loop through items added when using addWidget() to add to layout. However I can only access the 'inner layout' of type QWidgetIem Here's my code : - from PyQt4 import QtGui, QtCore import sys class Main(QtGui

Qt: How to remove the default main toolbar from the mainwindow?

寵の児 提交于 2019-12-08 00:55:36
问题 I am new to Qt, and I can't figure out why there is a draggable object in my main window. It starts at the top of the screen in its exapanded form. And then I can drag it and it shrinks into a square. 回答1: You need to remove the main toolbar from either QtDesigner as can be seen below or from the code manually: Then, you will need to rerun qmake for the changes to take effect as the ui_mainwindow.h header file needs to be regenerated from the updated mainwindow.ui description file. 来源: https:

QGraphicsItem move event - get absolute position

非 Y 不嫁゛ 提交于 2019-12-07 04:42:50
问题 I have a QGraphicsEllipseItem that I want to be movable and triggering signals on moving. So I subclassed QGraphicsEllipseItem and QObject and overrode the itemChange method to trigger a signal. That all seems to work but the positions that are reported seem to be relative to the old position of the item. Even if asking the item for its position seems only to retrieve the relative coordinates. Here is some code to make clear what I have done: class MyGraphicsEllipseItem: public QObject,

how to merge two images into one using QImage and QPainter in qt? [closed]

二次信任 提交于 2019-12-07 04:18:58
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . Hi I am developing a blackberry10 app. Inside the app I have two images and I just need to merge these two images into a single image. There is no function in Cascades to combine them. When I posted this in the blackberry developer forum I was advised to use QImage and QPainter functions in qt to combine two

How to override QApplication::notify in Qt

纵饮孤独 提交于 2019-12-06 20:25:26
问题 I am trying to handle exception in my Qt application, I went through a couple of posts which indicated of overriding the QApplication::notify method to handle exceptions in a efficient way in Qt. I am not sure where should I add this overriden method. Is it the mainwindow.h or main.cpp? I added the following function in my MainWindow.h: bool notify(QObject * rec, QEvent * ev) { try { return QApplication::notify(rec,ev); } catch(Tango::DevFailed & e) { QMessageBox::warning(0, "error", "error")

Qt: add a file selection field on the form (QLineEdit and “browse” button)

橙三吉。 提交于 2019-12-06 16:59:08
问题 I need to display QLineEdit with "Browse" button at my form. When user clicks button, QFileDialog should be opened, and so on. This is pretty common thing, but I can't find ready-made solution for that. I expected in Qt Designer some widget like QFileSelect , or something like that, but found nothing similar. Should I implement it by hand? Or, what is the correct way to do this? 回答1: Should I implement it by hand? Or, what is the correct way to do this? Yes, I agree with you that it is a

Qt: How to remove the default main toolbar from the mainwindow?

回眸只為那壹抹淺笑 提交于 2019-12-06 07:25:43
I am new to Qt, and I can't figure out why there is a draggable object in my main window. It starts at the top of the screen in its exapanded form. And then I can drag it and it shrinks into a square. You need to remove the main toolbar from either QtDesigner as can be seen below or from the code manually: Then, you will need to rerun qmake for the changes to take effect as the ui_mainwindow.h header file needs to be regenerated from the updated mainwindow.ui description file. 来源: https://stackoverflow.com/questions/27314748/qt-how-to-remove-the-default-main-toolbar-from-the-mainwindow

Qt 4.8 - QFileIconProvider, Getting icon for non-existent file (based on extension)

跟風遠走 提交于 2019-12-06 06:22:16
问题 I'm currently trying to get the icon based on a file extension, but it seems like QFileIconProvider will only return an icon if it can actually read an existing file. Is there any way I can get a QIcon based off of a file extension? One alternative would be to write a temporary file with the desired extension, but that is very inefficient so I'm looking for a way around. Any help would be appreciated! 回答1: Here's my solution for Windows: iconprovider.h: class IconProvider { public: static