qt,layout,svg , QT: add SvgWidget to layout

QT: add SvgWidget to layout


Tag: qt,layout,svg

I need to create circle tiles for a board game, so I made svgWigets and tried to add them to a layout for display them.

QLayout* layout = new QVBoxLayout;
QSvgWidget tile(":/gameIcons/white.svg");

But i get this error:

error: no matching function for call to 'QLayout::addWidget(QSvgWidget&)'

I guess svgWidgets are widgets, so i don't understand why this error happens, so i'm asking for the correct form to do it, i'm a novice anyway


You should use pointer to object, not whole object. So it should be:

QLayout* layout = new QVBoxLayout;
QSvgWidget *tile = new QSvgWidget(":/gameIcons/white.svg");

It can be also:

QLayout* layout = new QVBoxLayout;
QSvgWidget tile(":/gameIcons/white.svg");

But in this case tile creates in stack so it can be delete in your code (from your small code snippet I can't figure out where are you using this code so the best way is to use pointer) and tile will not be valid.


How to pass QString variable to QFile?

getData gets the chosen file from a QTreeView and displays it on label 'test', enables the 'Apply' button, which when clicked calls setTheme void OptionsDialog::getData(const QModelIndex &index) { QString selected = model2->filePath(index); ui->test->setText(selected); ui->pushButton_apply_theme->setEnabled(true); } void OptionsDialog::setTheme() { //char *file = selected->toLatin1().data(); //const std::string file = selected->toStdString(); QFile qss(selected); qss.open(QFile::ReadOnly);...

Customizing QDateEdit style

How can i get the appearance of QDateEdit as shown on the image? I tried changing the stylesheet, but I dont know how to achieve the spacing between the button and the edit, nor how can I change the down arrow button....

What's the layouts folder for in Rails?

I understand that .html.erb files go within app/views or its subfolders. But what is the app/views/layouts folder in particular for in Rails?

load a thumbnail on QListWidget with reduced resolution

I need to reduce the resolution of the images that I add and show in a QListWidgtet. Now I use the next code but it does not show all the images because they are being loaded with full resolution void ImagesWizard::on_pbAddImages_clicked() { QFileDialog dialog(this); dialog.setDirectory(mInitPath); dialog.setFileMode(QFileDialog::ExistingFiles); dialog.setNameFilter(trUtf8("Images (*.jpg *.png *.tif...

How to differentiate a QNetworkReply is aborted or not?

I have the following code: connect(&netMgr, SIGNAL(finished(QNetworkReply*)), this, SLOT(loadFinished(QNetworkReply*)), Qt::UniqueConnection); reply = netMgr.get(qheader); How could I tell whether the loadFinished(); slot is triggered by calling reply->abort() or not?...

How to avoid user to click outside popup Dialog window using Qt and Python?

I created a Dialog window using Qt Creator and Python. I would like that Window stays on the top of my Gui AND avoid users to click outside that Dialog Until this dialog was closed.

Repeat state on mouse click QML

Within the code I have a State, a Transition and a RotationAnimation defined. After the property change takes place, i.e. after the rotation is set to 360, the onClicked handler is rendered mute and the animation will never be played again after subsequent MouseArea clicks. Here is my current code:...

Border some cells in table via CSS

In a very basic table I would like to put a border around some specific cells. I created for instance this table: <?php echo '<link rel="stylesheet" type="text/css" href="style1tt.css">'; echo '<table>'; echo '<tr> <th>name</th> <th>score</th> <th>position</th></tr>'; echo '<tr> <td>Bart</td> <td>189</td> <td>2</td></tr>'; echo '<tr> <td>Shirley</td> <td>211</td> <td>1</td></tr>';...

How to add a gif image in the statusbar Qt [closed]

I'm pretty new to Qt and I was told that I can add a gif image to the status bar using the QMovie class. Can anyone tell how it can be done and is there any other way to do this too?

One controller uses its corresponding layout, but the other does not

My Rails project has two controllers, a SessionsController and a CustomersController. My project also has two layout views in the layouts directory, sessions.html.erb and customers.html.erb. I would like the SessionsController to render using the session.html.erb layout and the CustomersController to render using the customers.html.erb layout. I have removed all explicit...

Rotating a Label In Qt with Python

I'm somewhat new to Qt and was wondering how to rotate a Label that has a pixmap inside of it. I've tried somethings like this: def paintEvent (self, event): t = QtGui.QTransform() image = QtGui.QImage(_fromUtf8(":/icons/BOOM_OUT.png")) pixmap = QtGui.QPixmap.fromImage(image) self.label.setPixmap(pixmap) t.translate(400,300) t.rotate(45) p = QtGui.QPainter(self) p.setTransform(t) p.drawPixmap((-pixmap.width()/2),(-pixmap.height()/2), pixmap) p.end() I know...

connecting signals and slots with different relations

First of all I'd say I'm a noob to GUI programming. I use Qt 5.4. I came up with this code while watching voidRealms videos. connect(ui->horizontalSlider,SIGNAL(sliderMoved(int)),ui->progressBar,SLOT(setValue(int))); Obviously this connects slider movement with progressbar fill. This actually works like progressbarfill <- slidermovement. How can I make into a different relation? Like...

strange behaviour with UINavigationController and autolayout top layout guide

I am using auto layout for a controller under navigation controller. For this controller, I mainly have a scroll view inside the controller's view. the alignment rule for the scroll view is top layout guide, bottom layout guide, leading aligned with super view and trailing as well. the layout is...

Eclipse Layout: static instead of relative values?

I have a layout with two Buttons. One button is in the Center of the left half, and the other button is in the Center of the right side. But I use relative values (left="60dp" etc.). How can I have the same result with static values? Because I don't want...

How can I make a QTextEdit widget scroll from my program

I have a QTextEdit widget with a vertical scroll bar. report_text = new QTextEdit(); report_text->setAcceptRichText(true); report_text->setReadOnly(true); report_text->setTextInteractionFlags(Qt::NoTextInteraction); report_text->setAlignment(Qt::AlignTop); report_text->setWordWrapMode(QTextOption::NoWrap); report_text->setFrameStyle(QFrame::NoFrame); report_text->setMinimumSize(600, 380); report_text->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred); This is Qt 4.8 embedded. Now I...

Qstring error. Saving from Textpool to string

I've been trying to make simple 'typing game' where program is checking if input = showcased word. I'm trying to use Qt GUI, so I've placed two text widgets, and "play" button. However, there is a problem with string (or QString). Error: no match for 'operator=' (operand types are 'QString'...

How do you make a div only extend in one direction when the outer container size increases?

I'm trying to make a a page container with a navigation bar on the left (inside of the container). When the outer page is wider than the container, I would like just the navigation bar to extend left up to a certain size while the rest of the container's contents...

How can I wrap text in QGraphicsItem?

1) How can I wrap text in a QGraphicsTextItem to fit a fixed rectangle, with width and height ? Right now I am experimenting with creating a text, getting its bounding rectangle, and resizing it to fit the box - but I can't get wrapping. class TTT: public QGraphicsTextItem {...

Sorting based on the rules set by a string variable

In my hypothetical app, I receive a list of hotels from the server. struct Hotel { std::string name; // e.g. Hilton, Ritz int stars; // In range [0..5], 0 stands for "unrated" int freeRoomCount; // Number of available rooms [0..N] int parkingPlacesAvailable; // Number of parking places availalble [0..M] }...

How can I have an animated system tray icon in PyQt4?

I am trying to create an animated systray icon for a pyqt4 app but am having trouble finding any examples in python. This is the closest I can find but it's in C++ and I don't know how to translate it over: Is there a way to have (animated)GIF image...

Copy text and placeholders, variables to the clipboard

In my application I want generate random numbers or strings with a text in front of it. It is important for me that the text won't appear in my window, but instead gets copied to the clipboard. int randomnumber = rand() % 46 + 1; QClipboard *cb = QApplication::clipboard(); cb->setText("Just...

How to put a layout below other layout in Android

I have this code: RelativeLayout frame = new RelativeLayout(activity); RelativeLayout layout = new RelativeLayout(this); RelativeLayout.LayoutParams dateArea = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.MATCH_PARENT, 90); dateArea.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); DisplayMetrics displayMetrics = this.getResources().getDisplayMetrics(); int height = displayMetrics.heightPixels; RelativeLayout mapLayout = new RelativeLayout(this); RelativeLayout.LayoutParams mapParam = new RelativeLayout.LayoutParams(...

Dynamically Resizing Controls on Windows Forms

I has a winform which can be resize. I has 4 chart control in the form and sit side by side. When the form is in maximum size, the layout of each chart control is run out. I try to set the anchor style but i got no luck. How...

Id in database using qt

I am new to qt. I have created a table in sql, and what I'm trying to do is to give an id whenever user adds data. For the first thing inserted it will be 1, second 2 and so on. So how to check what number was the last...

Pro file directive: copy target to folder at build step

I have a TEMPLATE = subdirs project with 6 subprojects which build in specified order. I would like to copy the output file of project1 (it's target) to some folder. This folder is passed with LIBS += -L to project2 and project2 may use this file as a static library....

Update bindings to var properties in QML

If you take a look at this page it notes that bindings to var properties are not automatically updated when the object changes: Item { property var car: new Object({wheels: 4}) Text { text: "The car has " + car.wheels + " wheels"; } Component.onCompleted: { car.wheels = 6; }...

QEvent ownership

I want to send both predefined and custom QEvent to a Qt application. Is the event required be allocated on the heap or can I just pass the pointer to a object on the stack? QKeyEvent stackevent(QEvent::KeyPress); QKeyEvent* heapevent = new QKeyEvent(QEvent::KeyPress); QEvent * event; event = &stackevent; //valid ??...

An activity with two listviews in android

MainAcitivity public class MainActivity extends Activity { ListView list, listYear; String[] web = { "Google Plus", "Twitter", "Windows", "Bing", "Itunes", "Wordpress", "Drupal" } ; String[] year = { "2012", "2013", "2014", "2015", "2016", "2017", "2018" } ; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); list=(ListView)findViewById(R.id.list); list.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, web));...

How to use custom css file for layout of a module in Yii2

I am using basic pack of Yii2. I created a module named Admin and I want this module has it own layout but i don't know where to put all its css files. Then, how to include them in layout.php. My dirs like this: basic -- module -- admin --...

UICollectionView layout issue on iphone 5

I have a problem with my UICollectionView, I have 3 columns and everything works fine instead of iphone 5 and 4. In iphone 6 my collectionview looks that (width in cell): Iphone 5 with cells: The problem is, when in last row, I have 2 cells, and it looks like...

QT-FTP Upload Error

I'm trying to upload a simple txt file to ftp server but getting "QNetworkReply::ContentOperationNotPermittedError" reply from the server and i think it is about my file hierarchy. Here is the file order of my ftp server and my qt-ftp configuration : QUrl url("f13-preview.125mb.com/www/home/repo/test.txt"); url.setHost("f13-preview.125mb.com"); url.setUserName("1896230"); url.setPassword("mypassword"); url.setPath("f13-preview.125mb.com/www/home/repo/"); url.setScheme("ftp"); ...

java Swing: how to keep one component left aligned with another component centered with respect to parent

Say I have two components, A and B, in a JPanel. I want Component A to stay left aligned, while Component B does its best to stay in the middle of the panel. I mocked up the following demo (sorry for the quality, I made it in paint): What I...

QT Combo Box of Line Pattern

i want to make a line pattern combo box in Qt same as it is shown in the picture , please tell me is it possible to make a combo box in Qt like shown in the picture. Any help would be appreciated Regards ...

How can I override the member of (->) operator of a base class

Background: I have Qt generated UI classes with no common ancestor. I am subclassing a class (say, "Door") that uses one of these UI classes, and the derived class ("OakDoor") will use a different UI class, although much of the UI elements will have the same name. Until now I...

Unable to connect to mariadb database server with qt 4.8.5 and Ubuntu 12.04

I use the following code to connect to a MySQL server database. QSqlDatabase db_Server = QSqlDatabase::database("Test"); //find mysql driver db_Server = QSqlDatabase::addDatabase("QMYSQL","Test"); db_Server.setHostName("188.**.***.***"); db_Server.setPort(3306); db_Server.setDatabaseName("Test"); db_Server.setUserName("Test"); db_Server.setPassword("*********"); bool ret = db_Server.open(); if(ret) qDebug() << "Database open" else qDebug() << db_Server.lastError().text(); Lately they changed the server to mariadb and I assumed...

Return const reference to local variable correctly

Additionally to the answers 1, 2, 3 and GotW88, assume the following methods QString createString() { return QString("foobar"); } const QString& getString() { return createString(); } This will yield the famous "warning C4172: returning address of local variable or temporary" with VS2013. Now if i changed the second method to...

Is there a way to prevent Qt slider dragging beyond a value?

I have implemented the interface where the user is drawing a frame and then moving to next frame which will increment the slider value by 1. User can also increment or decrement the slider value. But, if user has drawn only upto frame 20 then user should not be able...

What does QHeaderView::paintSection do such that all I do to the painter before or after is ignored

This question is further development of this post and is different, though may seem similar as this one. I am trying to reimplement QHeaderView::paintSection, so that the background returned from the model would be honored. I tried to do this void Header::paintSection(QPainter * painter, const QRect & rect, int logicalIndex)...

How to set User Agent in QtWebEngine QML application

NOTE: I was able to do that on QtWebKit QML using the QtWebView extension. Here I am interested in using QtWebEngine. My simple test application import QtQuick 2.1 import QtQuick.Controls 1.1 import QtWebEngine 1.0 ApplicationWindow { width: 800 height: 600 color: "lightgray" visible: true WebEngineView { id: webview url:...

Must compile Opencv with Mingw in order to use in QT under Winodws?

I've visit these blogs https://zahidhasan.wordpress.com/2014/08/19/qt-5-3-1-64-bit-mingw-windows/ How to link opencv in QtCreator and use Qt library http://www.cnblogs.com/grandyang/p/4328896.html All of them are using Mingw to compile Opencv through Cmake. If I want to use Opencv in QT, is compiling with Mingw the only way? I have this question because I already compiled...

Using QSimpleXmlNodeModel and QTreeView

I've been looking at ways to populate a QTreeView with data from an XML file. The XML will be simple. I've come across QSimpleXmlNodeModel and have been trying to figure out if this is suitable for my needs, but can't find any examples of its use. Can someone point me...

Change attribute value of an XML tag in Qt

I'm trying to change the language attribute of a .ts file in Qt using Qt itself. Here is the sample XML format. <?xml version='1.0' encoding='utf-8'?> <!DOCTYPE TS> <TS language="es_ES" version="2.1"> ... </TS> I have tried different ways, but no luck. Here are the methods I used. FileIOError FileIO::changeLanguageOfTsFile( QString tsFileName,...

Updating ac value for Qtimer

I am using qt tool for mini2440. I make a gui for i2c adc having starti2c and stopi2c. All things are working well: it reads value of signal when starti2c button press, but I want this value to be updated. I know that Qtimer can be used, but how can...

change QDir::rootPath() to program running path?

I have a Qt FTP server that selects C:/ as root path. I'm trying to change that to select the starting program location path. For example: If ftpserver.exe is located in H:/programs/ftpserver.exe, it must automatically set the ftp root path to H:/. Code: ui->lineEditRootPath->setText(settings.value("settings/rootpath", QDir::rootPath()).toString()); Code: void MainWindow::on_toolButtonBrowse_clicked() { QString...

Loading animated gif data in QMovie

I'm very new to Qt (specifically PySide) and I'm trying write a script that loads an animated gif from file into a QByteArray and then into a QMovie. The reason for going from file to the QByteArray is because I cannot keep that gif file in memory. I want to...

How to change the opacity of Qt MainWindow?

How to change the opacity of the Qt MainWindow by some values? My main window contains nothing but just somehow I need to change the opacity using keystrokes. It looks like this now. I tried to set using this->setWindowOpacity(0.5); didn't get anything opacity effect. ...

QWidget.paintevent() vs QLabel.setPixmap()

I am trying to grab a widget and show it in another widget. Which one is less expensive? 1- using QWidget.paintevent() void MonitoringWidget::paintEvent(QPaintEvent *event) { if (m_mirrorWidget){ QPixmap mirrorPix = m_mirrorWidget->grab(); QPainter p(this); // p.drawPixmap(this->rect(),mirrorPix,mirrorPix.rect()); p.drawPixmap(ui->mirrorFrame->geometry(),mirrorPix,mirrorPix.rect()); update(); } return; } 2- QLabel.setPixmap()? QLabel mirrorLabel; QPixmap mirrorPix = m_mirrorWidget->grab(); mirrorLabel.setPixmap(mirrorPix )...

Change extends(layout) dynamically in laravel 5

I have been trying to change layout dynamically in laravel by just passing a variable in @extends('default1.master') to $var = default2 @extends('$var.master') possibly @extends($var.'.master') tried a lot but unable to find a solution all I get is error in my syntax or view not found....

C++ & Qt: Random string from an array area

In my small Qt application, I want to pick a random string out of an array after I clicked on a button. I've read many threads but nothing works for me. So in my slot there's an array with several strings in it. I also implemented <string>, <time.h> and srand....

Align horizontalcenter in Column

Column documentation explains how to achieve this: However, I would like to achieve this: That is, all items inside the Column should be horizontally aligned to the center. anchors.horizontalCenter: parent.Center does not work. How can I obtain the desired result?...