qt4

Qt best practice: append signals and slots to my main window or create new class

老子叫甜甜 提交于 2019-12-11 04:49:37
问题 Im just pondering best practice with an application I'm developing. Its a simple one window application using qt creator. It's just going to start a QProcess and show the output in a QTextEdit box. To do this there needs to be a bit of processing between the output of the QProcess and the QTextEdit but i dont know where i should do this, should i create a new class to do that or add member functions and extra signals and slots to my main window? I dont want mainwindow to become bloated and

Multi-dialog program in PyQT will not close (the sequel!)

心不动则不痛 提交于 2019-12-11 04:19:02
问题 I have another problem with PyQT, this time I have an example that will be far more useful since it contains part of my code (defanged of course!) I have a hard time figuring out how to close the 'PROGRAM SELECT' dialog window by only using the 'LOGOUT' button. I could simply use the close button on the form, but I want to do it with the 'LOGOUT' button. Could anyone help me solve this conundrum? Here is some compilable code for you all to chew on. connectionName = 'example' class

QGraphicsLineItem::paint() artifacts

不羁的心 提交于 2019-12-11 04:09:09
问题 I have my own class which inherits from QGraphicsLineItem and overrides the paint() method to draw a thick line with an arrow head: void MyGraphicsItem::paint( QPainter* aPainter, const QStyleOptionGraphicsItem* aOption, QWidget* aWidget /*= nullptr*/ ) { Q_UNUSED( aOption ); Q_UNUSED( aWidget ); QLineF cLine = line(); aPainter->setPen( QPen( Qt::black, 6, Qt::SolidLine ) ); aPainter->drawLine( cLine ); qreal lineAngle = cLine.angle(); const qreal radius = 2.0; QLineF head1 = cLine; head1

QGraphicsScene subclass is ignoring mouse press events

Deadly 提交于 2019-12-11 04:06:15
问题 I have a UI and a QGraphicsScene subclass GraphicsScene that implements mousePressEvent(), however mouse clicks are being ignored. ui->setupUi(this); scene = new GraphicsScene(this); scene->addPixmap(QPixmap::fromImage(someImage)); ui->graphicsView->setScene(scene); connect(scene, SIGNAL(clicked(QPoint)), this, SLOT(someSlot(QPoint))); GraphicsScene::mousePressEvent() is not called, and so does not emit signal clicked(). Is there something else I need to set to enable this? UPDATE: void

QFile::QFile function --> Error: QFile :: QFile (const QFile &) 'is private

青春壹個敷衍的年華 提交于 2019-12-11 04:04:02
问题 In one of my methods I need a QFile Object: void GUIsubclassKuehniGUI::LoadDirectory() { QString loadedDirectory = QFileDialog::getExistingDirectory(this, "/home",tr("Create Directory"), QFileDialog::DontResolveSymlinks); ui.PathDirectory -> setText(loadedDirectory); QFileInfo GeoDat1 = loadedDirectory + "/1_geo.m4"; QFileInfo GeoDat2 = loadedDirectory + "/2_geo.m4"; QString Value; if (GeoDat1.exists() == true) { QFile GEO = (loadedDirectory + "/1_geo.m4"); // ERROR LINE HERE! if(GEO.open

How to know which QLineEdit emitted the editingFinished() inside the signal handler?

这一生的挚爱 提交于 2019-12-11 03:35:59
问题 I want to implement a custom response to user input for several similar QLineEdit objects. I want to create a common handler of editingFinished() or textChanged() signal and assign it to all the QLineEdit s. However, the response requires the knowledge of the sender of the signal - for example, it must highlight the entered text with different colors. How do I know the sender of the signal inside it's handler? 回答1: You can get pointer to sender with call to QObject::sender() and then cast

QMenu: Set text color for specific QAction

て烟熏妆下的殇ゞ 提交于 2019-12-11 03:28:56
问题 I have a QMenu as context menu that looks like this: Menu - information_A - information_B - information_C Now i want the entry information_B to be painted in a different color. How can i archive this? 回答1: EDIT: I found the best solution in this post: link In your case it would be as simple as: QMenu contextMenu(this); QString menuStyle( "QMenu::item{" "color: rgb(0, 0, 255);" "}" ); contextMenu.setStyleSheet(menuStyle); For more options and possibilities take a look at the answer in the link

Displaying and sizing a grayscale from a QImage in Qt

拟墨画扇 提交于 2019-12-11 03:28:28
问题 I have been able to display an image in a label in Qt using something like the following: transformPixels(0,0,1,imheight,imwidth,1);//sets unsigned char** imageData unsigned char* fullCharArray = new unsigned char[imheight * imwidth]; for (int i = 0 ; i < imheight ; i++) for (int j = 0 ; j < imwidth ; j++) fullCharArray[(i*imwidth)+j] = imageData[i][j]; QImage *qi = new QImage(fullCharArray, imwidth, imheight, QImage::Format_RGB32); ui->viewLabel->setPixmap(QPixmap::fromImage(*qi,Qt:

QT4: How to restart application? Reset settings? [duplicate]

安稳与你 提交于 2019-12-11 03:26:01
问题 This question already has answers here : how to restart my own qt application? (8 answers) Closed 3 years ago . 1.) I would like to restart my QT4 application. Just a normal shutdown and start of the same application. 2.) Why? Well i need an Option to "reset" everything. To restart the application seems to be the easiest way to do this. The problem is, that there are a LOT of classes and everything. I dont have the time to put every setting of them back to standard, every textBox, Widget to

Deleting 'QNetworkReply *' returned by QNetworkAccessManager::post

牧云@^-^@ 提交于 2019-12-11 03:14:53
问题 QNetworkAccessManager::post function returns network reply object, is caller required to delete this or network access manager will take care of deleting it.? 回答1: From the documentation: Note: After the request has finished, it is the responsibility of the user to delete the QNetworkReply object at an appropriate time. Do not directly delete it inside the slot connected to finished(). You can use the deleteLater() function. 回答2: you can do it in slot if readyRead reply->abort(); reply-