qtgui

“QComboBox Pop-up” expanding and QtWebkit

我与影子孤独终老i 提交于 2019-12-05 21:32:15
问题 In Firefox/Chrome/InternetExplorer/Safari/Opera pop-ups from the combobox expand as the content, see Firefox picture: QComboBox pop-up does not expand the content. Pop-ups are limited by the size of QComboBox , see QWebView picture: So I implemented the QComboBox::showPopup : void newQComboBox::showPopup() { int width = this->width(); this->view()->setTextElideMode( Qt::ElideNone ); const int iconSize = this->iconSize().width(); const QFontMetrics fontMetrics = this->fontMetrics(); const int

QGraphicsItem move event - get absolute position

一世执手 提交于 2019-12-05 09:42:10
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, public QGraphicsEllipseItem { Q_OBJECT public: MyGraphicsEllipseItem(qreal x, qreal y, qreal w, qreal h,

How to override QApplication::notify in Qt

℡╲_俬逩灬. 提交于 2019-12-05 02:29:47
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"); } return false; } When I build my project I get the following error: error: cannot call member

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

风流意气都作罢 提交于 2019-12-04 22:37:35
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? Should I implement it by hand? Or, what is the correct way to do this? Yes, I agree with you that it is a common thing, but unfortunately you will need to implement this yourself. The good news is that you can do this

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

故事扮演 提交于 2019-12-04 12:48:11
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! Here's my solution for Windows: iconprovider.h: class IconProvider { public: static IconProvider * instance(); static QIcon fileIcon(const QString &filename); static QIcon dirIcon(); private:

Implementing a GUI Shell in qt

余生颓废 提交于 2019-12-04 06:35:31
问题 I want to implement a simple graphical shell in Qt using a QTextEdit . I want to get user commands and print the results in that QTextEdit . The code below returns the whole content of the QTextEdit : text_editor.toPlainText().toAscii(); But I don't know how to differentiate between what the user entered and what was printed before. What is the right way to do this? 回答1: Use QTextEdit for output. It supports multiple lines and you can control colors using HTML. Then use single line QLineEdit

“QComboBox Pop-up” expanding and QtWebkit

时光毁灭记忆、已成空白 提交于 2019-12-04 03:30:32
In Firefox/Chrome/InternetExplorer/Safari/Opera pop-ups from the combobox expand as the content, see Firefox picture: QComboBox pop-up does not expand the content. Pop-ups are limited by the size of QComboBox , see QWebView picture: So I implemented the QComboBox::showPopup : void newQComboBox::showPopup() { int width = this->width(); this->view()->setTextElideMode( Qt::ElideNone ); const int iconSize = this->iconSize().width(); const QFontMetrics fontMetrics = this->fontMetrics(); const int j = this->count(); for( int i=0; i < j; ++i ) { const int textWidth = fontMetrics.width( this->itemText

Menubar/ System tray app with Qt

风格不统一 提交于 2019-12-03 15:16:49
问题 I am new in Qt (PyQt) and I am trying to make an app whose functions will be executed from menubars/system trays. A perfect example is show here: I cannot find a good resource on how I can do this. Can someone advice. Thanks. 回答1: I think you are looking for working with QMenu and QMainWindow for the menu part, at least. Here you can find a C++ example: Menus Example and here a PyQt4 example: Menus and Toolbars in PyQt4 Here is the code inline for your convenience: import sys from PyQt4

Threaded OpenGL with shared QGLWidgets issue with Qt 5.1

a 夏天 提交于 2019-12-03 13:53:15
问题 I use two QGLWidgets. One for loading textures and one for rendering, but it is not working. I used the following explanation from http://blog.qt.digia.com/blog/2011/06/03/threaded-opengl-in-4-8/ Texture uploading thread Uploading many (or large) textures is typically an expensive operation because of the amount of data being pushed to the GPU. Again, this is one of those operations that can unnecessarily block your main thread. In 4.8 you can solve this problem by creating a pair of shared

Qt slider widget with tick text labels

蹲街弑〆低调 提交于 2019-12-03 12:21:29
问题 I'm searching for Qt widget like QSlider, but with text tick labels support like this: This widget I'll use as mode switcher. Have you met something like that? 回答1: I would use a QSlider with QLabel (s) attached as below. My usual disclaimer goes that you may need some fine-tuning and adjustment on your own for sure. main.cpp #include <QMainWindow> #include <QApplication> #include <QGridLayout> #include <QSlider> #include <QLabel> class MainWindow Q_DECL_FINAL : public QMainWindow { Q_OBJECT