Set QTabWidget Order by text of tabs - c++

I am trying to set tab order by tab text or tab name
ui.tabWidget->setTabOrder(//set order here by tab name like "helloTab","hiTab");
//I have tried this(I know it's dumb just trying)
ui.tabWidget->setTabOrder(ui.tabWidget->tabBar->findChild<QTab *>("tab_1"), ui.tabWidget->tabBar->findChild<QTab *>("tab_2"));
Till now no hope of getting this done. I am fairly new to qt.
Any Ideas or help would be helpful.

QTab is not defined in Qt. Use QWidget:
ui.tabWidget->setTabOrder(ui.tabWidget->tabBar->findChild<QWidget *>("tab_1"), ui.tabWidget->tabBar->findChild<QWidget *>("tab_2"));

Related

How to always open QComboBox popup downwards?

I'm using a stylesheet for my GUI elements such as the QComboBox and I need the popup to drop downwards which is not working at all. I'm working on a Linux based system. My Qt version is 5.4.2.
I already tried to set the style of the whole application with QApplication::setStyle("fusion") or QApplication::setStyle("cleanlooks") which apparently didn't seem to work.
The combobox looks like this:
As you can see the popup always covers the actual button but i need it to expand underneath.
I'd appreciate any help on this matter!
Thanks in advance,
Michael
Found out that it was a style issue. I had to start the application with the -style cleanlooks parameter.

Add some text to a QToolBar

I am having trouble adding some text in a QToolBar. I can only add Actions. Also I have two actions with their rerspectives icons in my QToolBar but I want to separate them and I canĀ“t either.
My newbie approach was to add empty actions to simulate blank spaces between the icons. But the user can click on the blank spaces.
I am using the Design function of QT Creator. Some help would be really apreciated.
It looks like you can't do it from within Designer:
https://bugreports.qt.io/browse/QTBUG-1267
That's an oooold suggestion, too, with a low priority to boot, so it probably won't get fixed any time soon.
You can get your hands dirty and do it in code, however.

Save the current position/order in a QTabWidget when a button is clicked - User Settings

Is it possible to save the current tab position/order in a QTabWidget in Qt?
What I want is basically to be able to let the users arrange the tabs as they like and then let them save the position so when they open the application again the tabs are where they were when last saved.
In the past I have done this put this only saves the window geometry.
QSettings mySettings("someName", "MyApp");
mySettings.beginGroup("MainWindow");
mySettings.setValue("geometry", saveGeometry());
mySettings.endGroup()
;
Any idea how or where can I find the information to get this done?
Thanks
Apparently there is no built-in way to do it, so you need to implement it. I don't see any possible troubles with it.
For example, you may obtain the index of each widget using QTabWidget::indexOf, or you may iterate over all tabs and obtain widgets using QTabWidget::widget, depending on which way is more convenient in your app.
When starting the app, sort your widgets by saved index and add them to the tab widget in that order.

Trying to clear a textEdit box in QT C++ (using QT Creator)

I'm new to QT, young at programming, and not understanding all the help materials for the classes in QT.
I have the following code, which executes on a button click, inserting text. This works fine but I want to clear the textEdit first, then insert the new text. Can anyone point me in the right direction here? Any help is much appreciated.
QTextCharFormat textFormat;
QTextCursor cursor(ui->textEdit->textCursor());
cursor.insertText("<some text to insert", textFormat);
It appears that I have to use setPosition() and movePosition() to select the text, then removeSelectedText() to clear it. I don't know how to determine the first and last positions in the document.
QTextEdit has a clear function, which deletes all text. In the documentation it's listed as a Slot.
QTextEdit::clear()

Opening a file from a Qt URL

I'm coding a small and basic error tracker with Qt. The whole application is in a QTable.
Each error is linked to a file ; so, one of the columns of my table deals with that. I have a QLabel and a button next to it ; you click on the button to select a file, and then, the label displays the name of the file.
What I'd like to do now : the QLabel appears as a link, and when you click on it, it opens the file (with whatever app is associated to the file's extension). I'd rather it in the form of a link, because it's more obvious for the user. If I don't manage to do it, I'll go with a home QLabel herited class with a click signal, but it's not quite the same thing.
So, is what I want to do possible ?
And how would you do it ? Thanks in advance for your help !
You can use html in QLabel's text, so lets use that. Then set the QLabel to automatically open the link:
ui->label->setText("Link to file");
ui->label->setOpenExternalLinks(true);