qt4

Keep widget on top in Qt

浪子不回头ぞ 提交于 2019-12-10 18:14:27
问题 I'm creating an application which has a "floating" widget which can be dragged around inside the application window. But it starts up, or tends to go behind other widgets sometimes. Is there any way to make sure that the widget in my application stays on top of all other widgets whenever it is made visible? Thanks. 回答1: Use the flag Qt::WindowStaysOnTopHint for your QWidget. This will force your widget to stay on top of all other windows 回答2: You can call raise() on your widget to make it

How to know that a file was opened ? QT

我的梦境 提交于 2019-12-10 17:47:40
问题 I want to know if a file was opened by user for reading (double click or open with ...), I am coding a C++ application with Qt Creator on Windows, after some research I found QFileSystemWatche, but it let me know only if a change was happened in the specific folder. void QFileSystemWatcher::fileChanged ( const QString & path ) [signal] This signal is emitted when the file at the specified path is modified, renamed or removed from disk. How to know if the file was opened? or is there a way to

Qt4 QSettings save enumeration value (for example Qt::CheckState)

末鹿安然 提交于 2019-12-10 17:45:26
问题 i wanna save state of QCheckBok in QSetting, i can cast its value to int but maybe exists more simple and proper method to do it? here is my code: QSetting setting; Qt::CheckState checkState; //... checkState = (Qt::CheckState)setting.value("checkState", Qt::Unchecked).toUInt(); //... setting.setValue("checkState", (uint)checkState); setting.sync(); 回答1: Firstly, try to avoid C-style casts. For example, replace the following line: checkState = (Qt::CheckState)setting.value("checkState", Qt:

Problems Installing Qt SDK on Mac OS X Lion

五迷三道 提交于 2019-12-10 17:40:08
问题 I've just upgraded to OS X Lion and am I trying to install Qt SDK. I've installed Qt 4.7.3 through homebrew, and am trying to get Qt SDK 1.1.1 running my machine. I downloaded the installer from the nokia Qt site, and run it. However, during the installation, a strange series of errors appeared: I clicked "Retry" a few times to no avail, so hit "Ignore", as "Cancel" just quits the installer. Again, clicked "Retry". Finally, clicked "Retry" again, and the installation completed. However, there

Display a QMessageBox from a QThread

孤街醉人 提交于 2019-12-10 17:35:39
问题 I want to display a message box from a separate thread, however, I get this error: QThread: Destroyed while thread is still running Can anyone explain how to display a message box from a thread? 回答1: Emit a signal. Since you cannot do UI stuff in a Qthread , instead send your message as an argument of your signal. signal decalaration in your qthread: signals: void write2SysStatus(QString theMessage); emitting the signal from the qthread: emit write2SysStatus("Some status"); slot declaration

Automatically disconnect after first signal emission

早过忘川 提交于 2019-12-10 17:13:10
问题 I am loading a web page from a file, then i replace some of the html in it: self.template_web_page = QtWebKit.QWebPage() self.template_web_page.mainFrame().load(QtCore.QUrl('template.html')) def load(ok): main_window.web_view.loadFinished.disconnect(load) self.table_element = self.template_web_page.mainFrame().findFirstElement("#table") self.table_element.setInnerXml(table_html) main_window.web_view.loadFinished.connect(load) Is there a way to connect to a signal just for one shot? 回答1: As

How to move to another window in Qt by a pushbutton

假如想象 提交于 2019-12-10 16:23:28
问题 I am using Qt Creator 2.0.1 based on Qt 4.7.0 (32bit). I am new to Qt. I created a mainwindow. How do I go to another window when I press the pushbutton in the main window? 回答1: I am able to do it well. I just give the code for anyone who need this. I have a window called MainWindow and a NewWindow . I have a button in Mainwindow called mMyButton . mainwindow.h is as follows. #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> //added #include"newwindow.h" namespace Ui { class

Qt: QWebview not displaying jpg, gif, png images on another machines

我怕爱的太早我们不能终老 提交于 2019-12-10 16:18:42
问题 Today I came across a very strange error with QWebView which I cannot resolve myself. I included a QWebView widget in my application. When I set a URL or a piece of HTML code to display (with QWebView::setUrl() or QWebView::setHtml() ), it works very well on my machine. It also works on all machines that have Qt installed, but not on those without it. I compiled a release build and included all necessary libraries as shared ( QtWebKit4.dll , QtNetwork4.dll etc.), so I guess my error lies in

QDockWidget layout with no central widget

六眼飞鱼酱① 提交于 2019-12-10 16:17:49
问题 I have a problem with QDockWidget. I'm using Qt Designer, and I would like to build an app with only dock-widgets, and have a small bar above for properties. The problem is that I cannot build the app without a main QWidget (I mean with only QDockWidgets). Here is my screenshot: Annotation 1) - this is the space that I can't remove. When I remove it from xml, Qt Designer crashes. If it is not removable, how can I set the left QDockWidget and the right QDockWidget to have half of the entire

Can QMessageBox::about adjust size to title length?

前提是你 提交于 2019-12-10 15:30:09
问题 I wanted to create a simple About dialog, but noticed that the QMessageBox::about does not adjust its size to the length of the title (which is usually longer due to the larger font ...at least in my desktop environment), only to the content. Is there a way to make sure that the dialog is made big enough to show all of the title as well? I could of course add white space to the aboutText, but I am hoping for a less hackish solution. Example: QString titleText("Some title which is slightly