Results 1 to 8 of 8

Thread: Enlarge Pushbutton?

  1. #1
    Join Date
    Dec 2007
    Posts
    129
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Enlarge Pushbutton?

    hi im trying to enlarge my push button when ever the mouse points at it.

    what should i do?

    im trying to use "mousemoveevent" but this event happen only when the mouse was "click", i dunno y?

    when you point the mouse pointer to the qpushbutton the border becomes orange and when gone back to default. i just want to do it like that, but change the size

    do i need to create a custom widget for push button?

  2. #2
    Join Date
    Jul 2007
    Location
    Germany
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Enlarge Pushbutton?

    Hello, you could try to enable mouse tracking for your button. It should then receive mouseMoveEvents without a clicked button.

    Arghargh

  3. #3
    Join Date
    Dec 2007
    Posts
    129
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Enlarge Pushbutton?

    im sorry i forgot to say that i already set the mouse tracking of all widgets to true.. my main widgets are a groupbox textedit label and button.. but mousemoveevent stiil require "click" plus a cant get the event->pos() inside my group box even i click it..
    Y?

  4. #4
    Join Date
    May 2008
    Posts
    42
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4

    Default Re: Enlarge Pushbutton?

    Hi Friend,

    Set MouseTracking to true. Then you can get the Mouse events.
    Then you mouseMoveEvent(QMouseEvent *event);

    So from event->pos(). you can get the current position of the mouse.
    Then change the geometry of your QPushButton.

  5. #5
    Join Date
    Dec 2007
    Posts
    129
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Enlarge Pushbutton?

    heres my code:
    .h
    Qt Code:
    1. #include <QMouseEvent>
    2. #include <QMainWindow>
    3. #include "ui_multibutton.h"
    4.  
    5. class multibuttonImpl : public QMainWindow, public Ui::multibutton
    6. {
    7. Q_OBJECT
    8. public:
    9. multibuttonImpl( QWidget * parent = 0, Qt::WFlags f = 0 );
    10. signals:
    11.  
    12. public slots:
    13. void add_item();
    14. void show_name();
    15. protected:
    16. [B]void mouseMoveEvent(QMouseEvent *);[/B]
    17. };
    To copy to clipboard, switch view to plain text mode 

    .cpp
    Qt Code:
    1. multibuttonImpl::multibuttonImpl( QWidget * parent, Qt::WFlags f)
    2. : QMainWindow(parent, f)
    3. {
    4. setMouseTracking(true);
    5. setupUi(this);
    6. }
    7.  
    8.  
    9. void multibuttonImpl::mouseMoveEvent(QMouseEvent *e)
    10. {
    11. QVariant mouse_pos=e->x();//globalPos();
    12. textEdit->append(mouse_pos.toString());
    13.  
    14. if (pushButton->underMouse()==true )
    15. pushButton->setGeometry(QRect(600, 210, 141, 101));
    16.  
    17.  
    18. }
    To copy to clipboard, switch view to plain text mode 

    note: i setmousetracking=true in all my widget in my .ui but "mousemoveevent" still requires "click"

    note again: im using a group box
    Last edited by triperzonak; 20th June 2008 at 08:12.

  6. #6
    Join Date
    Dec 2007
    Posts
    129
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Enlarge Pushbutton?

    i think i found now the problem.. its in my group box, i try to change the groupbox into frame and now its working..

    tnx.. but y is it like that?

  7. #7
    Join Date
    Dec 2007
    Posts
    129
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Enlarge Pushbutton?

    weee.. i try to create dynamicaly the pushbutton and add it to frame but now its not working requires "drag click" again help...

    .h
    Qt Code:
    1. #ifndef MULTIBUTTONIMPL_H
    2. #define MULTIBUTTONIMPL_H
    3. //
    4. #include <QMouseEvent>
    5. #include <QMainWindow>
    6. #include "ui_multibutton.h"
    7. //
    8. class multibuttonImpl : public QMainWindow, public Ui::multibutton
    9. {
    10. Q_OBJECT
    11. public:
    12. multibuttonImpl( QWidget * parent = 0, Qt::WFlags f = 0 );
    13. signals:
    14.  
    15. public slots:
    16. void add_item(int num_of_item);
    17. void show_name();
    18. protected:
    19. void mouseMoveEvent(QMouseEvent *);
    20. };
    21. #endif
    To copy to clipboard, switch view to plain text mode 

    .cpp
    Qt Code:
    1. #include "multibuttonimpl.h"
    2. #include "custom_button.h"
    3. #include <QMessageBox>
    4. #include<QVariant>
    5. #include <QPushButton>
    6. #include <QCoreApplication>
    7.  
    8. int item_number;
    9. int pos_x=20,pos_y=20,max_x=300;
    10.  
    11. struct push{
    12. int num;
    13. QPushButton *button;
    14. int xpos,ypos;
    15. QString itemcode;
    16. };
    17. push pushes[30];
    18.  
    19. multibuttonImpl::multibuttonImpl( QWidget * parent, Qt::WFlags f)
    20. : QMainWindow(parent, f)
    21. {
    22. setMouseTracking(true);
    23. setupUi(this);
    24. add_item(12);
    25. }
    26.  
    27. void multibuttonImpl::add_item(int num_of_item)
    28. {
    29. QVariant item_num;
    30. item_number=num_of_item;
    31.  
    32. for (int i=0;i<num_of_item;i++)
    33. {
    34. b="item";
    35. item_num=i+1;
    36. pushes[i].num=i;
    37. b.append("_"+item_num.toString());
    38.  
    39. pushes[i].button =new QPushButton(frame);
    40. pushes[i].button->setObjectName(b);
    41. pushes[i].button->setCheckable(true);
    42. pushes[i].button->setChecked(false);
    43. pushes[i].button->setGeometry(QRect(pos_x, pos_y, 121, 81));
    44. pushes[i].button->setText(b);
    45. pushes[i].button->setCursor(QCursor(Qt::PointingHandCursor));
    46. pushes[i].button->setMouseTracking(true);
    47. //pushes[i].button->setStyleSheet("border-image: url(:/icons/itemlogo.png);");
    48. pushes[i].xpos=pos_x;
    49. pushes[i].ypos=pos_y;
    50. connect (pushes[i].button, SIGNAL (clicked(bool)),this , SLOT (show_name()));
    51.  
    52. if (pos_x==max_x)
    53. {
    54. pos_y+=100;
    55. pos_x=20;
    56. }
    57. else
    58. pos_x+=140;
    59. }
    60. }
    61.  
    62. void multibuttonImpl::show_name()
    63. {
    64. for (int j=0;j<item_number;j++)
    65. {
    66. if (pushes[j].button->isChecked())
    67. {
    68. //pushes[j].button->setStyleSheet("");
    69. pushes[j].button->setChecked(false);
    70. //QMessageBox::information(this, tr("name"),pushes[j].button->objectName()+" ");
    71. }
    72. }
    73. }
    74.  
    75. void multibuttonImpl::mouseMoveEvent(QMouseEvent *e)
    76. {
    77. for (int j=0;j<item_number;j++)
    78. {
    79. if (pushes[j].button->underMouse()==true)
    80. pushes[j].button->setGeometry(QRect(pushes[j].xpos-10,pushes[j].ypos-10, 131, 91));
    81. else
    82. pushes[j].button->setGeometry(QRect(pushes[j].xpos, pushes[j].ypos, 121, 81));
    83.  
    84. }
    85. }
    To copy to clipboard, switch view to plain text mode 


    help help help y is "mousemoveevent" not working?

  8. #8
    Join Date
    Dec 2007
    Posts
    129
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Enlarge Pushbutton?

    now i found the answer on my question but created again another question..

    after i remove the frame and put my dynamic buttons directly to the centralwidget like
    Qt Code:
    1. pushbutton= new QPushButton(this)
    To copy to clipboard, switch view to plain text mode 
    it works!..

    however y is it like that? if i put a button on a groupbox mouseevent inside it is not working.. if i put the buttons on a frame and dynamically create the buttons "mousemoveevent" is more like "mousepressevent" y?

    until this time i have no problems but if i further improve my project i will have.. I cant put background image on my buttons alone cause i have no frame or groupbox it will affect the whole form.. hayyzzzzzz

    note: just to clarify i setmousetracking on groupbox and frame as true, it is not the problem..

Similar Threads

  1. Problem with setFont for a PushButton
    By arunvv in forum Newbie
    Replies: 12
    Last Post: 7th April 2008, 23:35
  2. small round pushbutton
    By sm in forum Newbie
    Replies: 3
    Last Post: 5th February 2008, 09:08
  3. connecting image to a pushbutton
    By sudheer in forum Qt Tools
    Replies: 2
    Last Post: 4th December 2007, 09:23
  4. Replies: 1
    Last Post: 2nd July 2007, 16:29
  5. why pushbutton moving??
    By Shuchi Agrawal in forum Qt Tools
    Replies: 7
    Last Post: 19th January 2007, 17:17

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.