qt4

Check if directory is empty

半城伤御伤魂 提交于 2019-12-22 06:34:31
问题 I'm trying to check if a directory is empty. MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); QDir Dir("/home/highlander/Desktop/dir"); if(Dir.count() == 0) { QMessageBox::information(this,"Directory is empty","Empty!!!"); } } Whats the right way to check it, excluding . and .. ? 回答1: Well, I got the way to do it :) if(QDir("/home/highlander/Desktop/dir").entryInfoList(QDir::NoDotAndDotDot|QDir::AllEntries).count() == 0) { QMessageBox:

Qt4 custom window frames like in office 2007?

不羁岁月 提交于 2019-12-22 06:06:52
问题 is there a way to force Qt4 to draw window frame similar to office 2007/2010 ? I want my application to look the same in all windows versions not just vista/7. Maybe there is some extension to QMainWindow ? Thanks for help. 回答1: You have to remove the titlebar and implement it yourself. It is part of the window manager. It is supplied depending on the OS you are running under (Windows, OSX, Linux...). It can be removed by setting the WindowFlags http://doc.trolltech.com/4.2/qwidget.html

Qt 4.6 Adding objects and sub-objects to QWebView window object (C++ & Javascript)

倾然丶 夕夏残阳落幕 提交于 2019-12-22 05:25:09
问题 I am working with Qt's QWebView, and have been finding lots of great uses for adding to the webkit window object. One thing I would like to do is nested objects... for instance: in Javascript I can... var api = new Object; api.os = new Object; api.os.foo = function(){} api.window = new Object(); api.window.bar = function(){} obviously in most cases this would be done through a more OO js-framework. This results in a tidy structure of: >>>api ---------------------------------------------------

Qt 4.6 Adding objects and sub-objects to QWebView window object (C++ & Javascript)

喜夏-厌秋 提交于 2019-12-22 05:25:08
问题 I am working with Qt's QWebView, and have been finding lots of great uses for adding to the webkit window object. One thing I would like to do is nested objects... for instance: in Javascript I can... var api = new Object; api.os = new Object; api.os.foo = function(){} api.window = new Object(); api.window.bar = function(){} obviously in most cases this would be done through a more OO js-framework. This results in a tidy structure of: >>>api ---------------------------------------------------

catch link clicks in QtWebView and open in default browser

泄露秘密 提交于 2019-12-22 05:01:02
问题 I am opening a page in QtWebView (in PyQt if that matters) and I want to open all links in the system default browser. I.e. a click on a link should not change the site in the QtWebView but it should open it with the default browser. I want to make it impossible to the user to change the site in the QtWebView. How can I do that? Thanks, Albert 回答1: That does it: import sys, webbrowser from PyQt4.QtCore import * from PyQt4.QtGui import * from PyQt4.QtWebKit import * app = QApplication(sys.argv

Multiple definitions error: one in my file and one in the moc file.

筅森魡賤 提交于 2019-12-22 04:47:18
问题 I have a class called FindAndReplaceBar, whose implementation is this: #include "FindAndReplaceBar.h" #include <QLabel> #include <QPushButton> #include <QGridLayout> #include <QTextDocument> #include <QLineEdit> FindAndReplaceBar::FindAndReplaceBar(QObject *parent) : QToolBar(NULL) { lblFind = new QLabel("Find: ",this); lblReplace = new QLabel("Replace",this); ledtFind = new QLineEdit(this); ledtReplace = new QLineEdit(this); QPixmap next(":/res/resources/next.gif"); QPixmap previous(":/res

QComboBox inside QTreeWidgetItem

点点圈 提交于 2019-12-22 04:31:24
问题 Is there something similar to the (PyQT) QTreeWidgetItem.setCheckState(0, Qt.Checked) but for the combo box? I can't see anything in the reference, so how can I insert a custom QComboBox as one of the elements within QTreeWidgetItem? 回答1: Use QTreeWidget::setItemWidget ( QTreeWidgetItem * item, int column, QWidget * widget ) to put the combo box into the cells. For example, let's make all rows of the second column of a 2-column QTreeWidget to all be combo boxes: QTreeWidgetItemIterator it(ui-

About using an undocumented class in Qt

痴心易碎 提交于 2019-12-22 04:28:24
问题 Is it safe to use the undocumented QObjectUserData class and the QObject::setUserData in Qt? 回答1: Instead you could look at using QObject::setProperty, this allows you to set not only compile time declared properties, but also dynamic properties which do not need to be declared before use. This allows you to attach arbitrary values to QObjects at run time, similar to user data. 回答2: In general you should not rely upon undocumented APIs. If you ever plan on upgrading Qt, then don't use it! 回答3

How to place one widget over another in Qt

亡梦爱人 提交于 2019-12-22 03:48:43
问题 i have a window in Qt, on that i am drawing a picture. now i want to place the progressbar over it. how can i do that?.. steps i am following to do Create a window, Draw picture in paint event of window Then create QGridLayout layout, add your window Display over it. suppose i want to add progress bar, over a portion of picture window. how can i do that i dont think its possible to implement in window paint event. please assist me Thanks 回答1: You can add the progress bar as child of your

How to get the row number of widget placed in a cell of Qtablewidget when it get clicked?

南楼画角 提交于 2019-12-21 21:34:58
问题 What i'm trying is to get the row number of QcomboBox when user selects items. Although its easy to to get the cell column and row using cellClicked(int,int) signal, but it only works when there is no widget on the cell. so how to get the row number in case if there is a widget placed in a cell. Note: All the combobox are added dynamically 回答1: At-last i found 2 ways of doing it. By setting the property of QComboBox Using the QSignalMapper First Method QComboBox* mCombo = new QCombobox();