Results 1 to 6 of 6

Thread: Emulating Unix on Windows

  1. #1
    Join Date
    Feb 2008
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Emulating Unix on Windows

    I am working on a project where I have to simulate a Unix environment in my Windows application. That is, I want to have the active component automatically change to be the window or control under the cursor. Specifically, I need to have the space bar press the button under the cursor (for all buttons on all windows in my application). My first question is: Is there any way to turn on a "focus when mouse over" policy in QT (either globally or on a per control basis)?

    Since I could not find a "focus when mouse over" ability in QT, as a test case, I tried to create MyHoverButton derived from QPushButton. In order to use MyHoverButton I changed QPushButton to MyHoverButton in one of my Dialog.ui files. However, when QT tried to process this file it placed "#include <MyHoverButton.h>" in the ui_dialog.h file. Since, MyHoverButton.h is in my project's directory and not the System or QT directory, the code will not compile. I could change the line in the ui_dialog.h to #include "MyHoverButton.h" however, the next time QT compiles the .ui file, it will place the "#include <MyHoverButton.h>" line back in the file. My second question is: How can I change the class defined in the QT designer from the standard QT control (like QPushButton) to a custom control derived from the standard control in a way that does not break the QT designer?

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Emulating Unix on Windows

    Quote Originally Posted by eichner View Post
    Since I could not find a "focus when mouse over" ability in QT, as a test case, I tried to create MyHoverButton derived from QPushButton. In order to use MyHoverButton I changed QPushButton to MyHoverButton in one of my Dialog.ui files. However, when QT tried to process this file it placed "#include <MyHoverButton.h>" in the ui_dialog.h file. Since, MyHoverButton.h is in my project's directory and not the System or QT directory, the code will not compile. I could change the line in the ui_dialog.h to #include "MyHoverButton.h" however, the next time QT compiles the .ui file, it will place the "#include <MyHoverButton.h>" line back in the file. My second question is: How can I change the class defined in the QT designer from the standard QT control (like QPushButton) to a custom control derived from the standard control in a way that does not break the QT designer?
    This is the correct way to go.
    In Designer, you must promote the QPushButton to your custom widget, then you will be asked for the header. Don't do it manually.

  3. #3
    Join Date
    Feb 2008
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Emulating Unix on Windows

    Thanks for the tip. I did not know about the "Promote" feature of QT. Promoting the QPushButton worked great!! I now have a push button which has focus whenever the mouse is over it!

    I would like to do this for ALL widgets in my application. Is there any way to override the QWidget class from which all of the other widgets are derived? Or must I write MyHoverComboBox, MyHoverLineEdit, MyHoverCheckBox, ... classes?

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Emulating Unix on Windows

    No direct way.
    You have to create a subclass for every widget you want to behave differently.

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Emulating Unix on Windows

    I think it could be done either by sublassing QApplication and re-impelementing notify() or installing an event filter on the application object.
    J-P Nurmi

  6. #6
    Join Date
    Feb 2008
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Emulating Unix on Windows

    Thanks for the help.

    I went ahead and created MyHoverCheckBox, MyHoverComboBox, and MyHoverLineEdit to cover most of the controls. I will address lists and tables later.

    The code to do this is pretty simple. I even created a MyHoverDialog derived from QDialog so my Windows application has a real Unix feel to it.

    The only remaining problem is ,in Windows, when a dialog is made visible it is automatically given focus. So ... when achild window is created which is not under the cursor the "wrong" window has focus until I move the mouse over one of my controls which changes the "active control". I thought about overriding the "showEvent" method to try and counteract this but, the problem is more complicated then it seems - because the new child window may or may not need focus (depending on whether the current cursor position is within the bounds of the window). And the documentation on the "showEvent" method says that it is called before the dialog is shown. So, I do not know if the diaglog's data (e.g. geometry) is valid.

Similar Threads

  1. Windows not appearing in XP.
    By beardybloke in forum Qt Programming
    Replies: 7
    Last Post: 24th October 2007, 18:32
  2. distinguish windows and unix in Makefile
    By magland in forum General Programming
    Replies: 1
    Last Post: 4th April 2007, 20:43
  3. Strange problem with events on Unix
    By sukanyarn in forum Qt Programming
    Replies: 2
    Last Post: 7th November 2006, 03:45
  4. converting unix exe to windows binary
    By deekayt in forum General Programming
    Replies: 2
    Last Post: 17th September 2006, 02:00
  5. Qt and windows vista
    By munna in forum General Discussion
    Replies: 8
    Last Post: 11th January 2006, 23:33

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.