[Qt-interest] QMainWindow: setWindowTitle() & setWindowIcon() don't work

Constantin Makshin dinosaur-rus at users.sourceforge.net
Thu Dec 11 21:44:34 CET 2008


Couldn't you provide some minimal example that suffers from this issue so  
other people could test it? I don't have any problems with neither  
setWindowTitle() or setWindowIcon() for QMainWindow.

On Thu, 11 Dec 2008 20:38:48 +0300, Miguel Cardenas <mfcardenas at gmail.com>  
wrote:
> Hi list
>
> I made a small application with the new Qt4 to see the changes respect
> Qt3... it is finished and working so decided to play with the title bar  
> and found that setWindowTitle() & setWindowIcon() don't work with  
> QMainWindow...
>
> My first code was like this:
>
> #include "my_pixmap.xpm"
>
> MainWindow::MainWindow (QApplication* app) {
>    setWindowTitle(tr("some title"));
>    setWindowIcon(QIcon(QPixmap(my_pixmap)));
>    ...
> }
>
> then replaced by this one:
>
> MainWindow::MainWindow (QApplication* app) {
>    setWindowTitle(tr("some title"));
>    QApplication::setWindowIcon(QIcon(QPixmap(my_pixmap)));
>    ...
> }
>
> but it sets the same icon for all my windows, by now it is okay but what  
> if I want it only for my current QMainWindow?
>
> Respect the setWindowTitle() it didn't work in any tested way, it is  
> always the name of the executable file..
>
> Tried these combinadions and any worked:
>
> setWindowTitle(tr("some title"));
> setWindowTitle(QString("some title"));
> setWindowTitle(QString(tr("some title")));
>
> QString title("some title");
> setWindowTitle(title);
>
> QString title(tr("some title"));
> setWindowTitle(title);
>
> and nothing, the title remains as the executable filename. The  
> documentation says QMainWindow inherits QWidget that has available both  
> setWindowTitle() and setWindowIcon() so it should work, but no, the icon
> only could be modified via the QApplication::setWindowIcon() and the
> title in any way.
>
> What is wrong in this code?
>
> Thanks

-- 
Constantin "Dinosaur" Makshin



More information about the Qt-interest-old mailing list