qt4

How to show icons without text in QListWidget?

*爱你&永不变心* 提交于 2019-12-12 10:56:24
问题 I want to show only icons in my QListWidget. I set text to empty string. When I select an icon I see an empty selected square on the text place. See the screenshot How can I get rid of this empty space?! 回答1: use NULL instead ui->listWidget->addItem(new QListWidgetItem(QIcon(":/res/icon"),NULL)); 回答2: How do you add an icon in your QListWidget? This should work fine (I am loading the icon from the resource file) : ui->listWidget->addItem(new QListWidgetItem(QIcon(":/res/icon"), "")); EDIT

QNetworkAccessManager: post http multipart from serial QIODevice

懵懂的女人 提交于 2019-12-12 10:43:27
问题 I'm trying to use QNetworkAccessManager to upload http multiparts to a dedicated server. The multipart consists of a JSON part describing the data being uploaded. The data is read from a serial QIODevice, which encrypts the data. This is the code that creates the multipart request: QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType); QHttpPart metaPart; metaPart.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); metaPart.setHeader(QNetworkRequest:

Enable QLabel to shrink even if it truncates text

自古美人都是妖i 提交于 2019-12-12 10:36:49
问题 How can I get a QLabel to be resized even if it means truncating its containing text? I have a QLabel stretching the whole horizontal space of a Widget. When setting its text I make sure it is correctly truncated, ie getting its FontMetrics and Width and using metrics.elidedText(). But when the user resizes the widget the Label doesn't allow it to shrink any further since it would truncate its text. Any ideas how to solve this? The simplest solution I think would be to somehow tell the QLabel

How to set QMainWindow as the modal one?

我与影子孤独终老i 提交于 2019-12-12 09:49:40
问题 I am using QMainWindow for GUI development of my project..One problem I am Stuck with is blocking all other visible windows from getting input, while one is in operation. I can not use QDialog.Because rich features of QMainWindow is required. How can I declare a particular window as modal? I tried with QWidget::setWindowMOdality() . Here is a demo program, what I tried but it didnt work. #include <QApplication> #include <QMainWindow> #include <QPushButton> int main(int argc, char **argv){

Counting file in a directory

本秂侑毒 提交于 2019-12-12 09:40:58
问题 I want to count number of file in a directory, I used count method in QDir class but it always return number of file plus two! why does it do this work ? thanks 回答1: QDir.count() returns the total count of files and directories in the directory. This includes the . (this) and .. (parent) directory entries. So the count is always two more than the "real" files and subdirectories. 回答2: You should use flags QDir::Filters with QDir::NoDotAndDotDot 回答3: I am posting a complete answer. QString path

How to overload operator<< for qDebug

本秂侑毒 提交于 2019-12-12 09:29:33
问题 I'm trying to create more useful debug messages for my class where store data. My code is looking something like this #include <QAbstractTableModel> #include <QDebug> /** * Model for storing data. */ class DataModel : public QAbstractTableModel { // for debugging purposes friend QDebug operator<< (QDebug d, const DataModel &model); //other stuff }; /** * Overloading operator for debugging purposes */ QDebug operator<< (QDebug d, const DataModel &model) { d << "Hello world!"; return d; } I

How do I use foreach with QDomNodeList in Qt?

。_饼干妹妹 提交于 2019-12-12 08:24:29
问题 I'm new to Qt and I'm learning something new every day. Currently, I'm developing a small application for my Nokia N900 in my free time. Everything is fine, I am able to compile and run Maemo applications on the device. I've just learned about the foreach keyword in Qt. (I know it is not in C++, so I didn't think about it until I accidentally stumbled upon a Qt doc that mentioned it.) So, I decided to change my quite annoying and unreadable loops to foreach, but I failed with this:

QSignalMapper and original Sender()

北战南征 提交于 2019-12-12 07:27:10
问题 I have a bunch of QComboBox es in a table. So that I know which one was triggered I remap the signal to encode the table cell location (as described in Selecting QComboBox in QTableWidget) (Why Qt doesn't just send the cell activated signal first so you can use the same current row/column mechanism as any other cell edit I don't know.) But this removes all knowledge of the original sender widget. Calling QComboBox* combo = (QComboBox* )sender() in the slot fails, presumably because sender()

QT4 How to blur QPixmap image?

微笑、不失礼 提交于 2019-12-12 07:18:43
问题 QT4 How to blur QPixmap image? I am looking for something like one of the following: Blur(pixmap); painter.Blur(); painter.Blur(rect); What is the best way to do this? 回答1: 1st) declare external QT routine: QT_BEGIN_NAMESPACE extern Q_WIDGETS_EXPORT void qt_blurImage( QPainter *p, QImage &blurImage, qreal radius, bool quality, bool alphaOnly, int transposed = 0 ); QT_END_NAMESPACE 2nd) Use: extern QImage srcImg;//source image QPixmap pxDst( srcImg.size() );//blurred destination pxDst.fill( Qt

Qt Linguist - set translator for application

断了今生、忘了曾经 提交于 2019-12-12 06:04:15
问题 how can i start creating a ts file that my application will use? in the options of Linguist i can't create a new one with my own words and translation.... i can only translate a ts file that is allready exist. 回答1: First, in your project, you need to write texts with tr() if you wanna translate them. For example QPushButton button(tr("Button")); In your pro file, add TRANSLATIONS = chinese.ts\ italian.ts These files will be created automatically later. Second, go to Qt Command Prompt. Go to